Error: Must use import to load ES Module #2137
-
When I run the compiled code from TypeScript into JS, I get the following error:
My tsconfig.json {
"compilerOptions": {
"target": "ESNext",
"moduleResolution": "Node",
"module": "commonjs",
"strict": true,
"strictNullChecks": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./build/",
"removeComments": true
}
} My package.json {
"name": "autopost-lolz",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Keller",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.7.10",
"@types/request": "^2.48.7"
},
"dependencies": {
"lit-html": "^1.4.1",
"node-html-parser": "^4.1.4",
"request": "^2.88.2"
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
My guess would be that the issue is that your TypeScript config is telling TypeScipt to use CJS.
That would explain the error message, in that TypeScript is under the hood using Here's some more info on the expectations of lit for development that might provide more info And TypeScript docs on the subject as well |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
All I needed was syntax highlighting, so the first thing I got was your module. I found an extension for VSCode that doesn't even need to put modules in Node.JS.
Problem solved :)