-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ERROR] Must use import to load ES module #314
Comments
I'm having the same problem ts-node-dev version: 2.0.0 |
Switched to babel with @babel/preset-typescript, and nodemon. Everything is working there. Can use imports without filenames, can use directories with implied index.ts, and can use mongoose. Will try other packages later to confirm that everything works now. |
Still having this issue with ts-node-dev. No matter what I try (type: "module" in package.json, module:"esnext" and module:"commonjs" in tsconfig.json, etc.) Right now, my problem is with the package inquirer. It's ready for ESM in new version v9.0.0. But if I remove type: "module" from package.json, inquirer complains. Then I replaced the import with a dynamic import await import('inquirer'), but then I get an error that can't use top level await with a commonjs module... It's a paradox. But with babel and nodemon, and babel typescript presets it works flawlessly. I'm reaching the conclusion that ts-node-dev isn't ready for ESM so I will continue using babel and nodemon. |
I have this exact same problem too, would it be possible to support this? |
Same problem. |
You can try this config, I tested it with most ES2022 features (including Top Level Await) and it works. {
"type": "module",
"name": "test_typescript_esm",
"version": "1.0.0",
"description": "",
"scripts": {
"dev": "nodemon -I --exec node --experimental-specifier-resolution=node --loader ts-node/esm ./src/main.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nodemon": "^2.0.19",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"exports": "./dist/index.js",
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/node": "^7.17.10",
"@babel/plugin-proposal-decorators": "*",
"@babel/preset-env": "^7.18.2",
"@types/node": "^18.6.2"
}
}
|
mark |
Same problem here. I tried with ts-node-esm --experimental-specifier-resolution=node --transpile-only ./src/index and it works BUT it'll not restart automatically if files will change |
UpdateBesides it working with Babel, I achieved to make it working with Install nodemon and ts-node and of course typescript, set {
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "Node",
"module": "ESNext",
"target": "ESNext"
}
} And then: |
package.json
tsconfig.json
|
Thank you! |
Replace ts-node-dev with nodemon + ts-node: wclr/ts-node-dev#314 (comment)
Replace ts-node-dev with nodemon + ts-node: wclr/ts-node-dev#314 (comment)
According to the typescript documentation the
So the |
I'm using tsx now. No issues so far. But thanks for the update. I'm gonna try ts-node-dev again with module resolution set to nodenext. Is the ts-node set to esm mandatory? |
@angelhdzmultimedia Wow,
Unfortunately, I don't quite understand your question. To make ts-node compatible with ESM, we should use the appropriate loader in one of the following ways, but P.S. We are looking forward to ESM support in |
My question is, is it mandatory to add this: And yes, you're right about tsx. I've been also using I'm exited to see ts-node-dev being improved. |
@angelhdzmultimedia,
We should somehow tell 1. Specify in
|
I appreciate your kind responses A LOT!!! They have been on fire🔥, on point👌! Sorry to bother you with one last question... ❔ Difference between Wishing you health, peace, and success! |
Seems that I don't see any of them being deprecated at the moment. So you can use any of these methods that you like best. |
Got one-liner working with nodemon: npx nodemon -e ts,json --exec 'node --experimental-specifier-resolution=node --loader ts-node/esm' <path>.js |
not working on windows :( |
Thanks to your suggestions I got it working! There is one thing I didn't get, I'm using TS, why do I need to import file adding the extension and this extension has be in
|
@RicFer01 Your last question have the answer here: https://www.typescriptlang.org/docs/handbook/esm-node.html |
Thank you! |
Are you using it in conjunction with docker? My tsx doesn't work watch mode in the container. |
Repo is looking stale, fair to say this isn't getting fixed any time soon? |
and still nothing? |
same error here |
I solved my problem by simply removing "type" : "module" from package.json |
if anyone want an alternative, i use tsx for about sometime and i love it, simple to use and maintained. |
Sorry, but this is not a solution. |
+1 for |
For me it is. Works fine. My package.json:
|
It worked well for me!
|
I recognize this may not be optimal for performance, but it's simpler to set up. I might revise this approach in the future. Found the command here: wclr/ts-node-dev#314 (comment)
This is good! Thanks |
It is built on top of ts-node, and ts-node is a ... please search on stackoverflow for solutions like |
I'm lately using And in And works... good... |
i solved this problem removing "type": "module" from my package.json and keeping just "module": "CommonJS" on my tsconfig.json. it works fine. |
Bun for Windows is out guys! 🔥👀✌️🤣 Bun, tsx, unjs/jiti. Solid options now. Closing this. |
I solved this problem by running npm update ts-node-dev |
Hi guys! I just solved the same problem by generating tsconfig ( Here is my package.json: Here is my tsconfig.json: I'll be glad if this helps someone 🙂 |
Issue description
Context
Totally new Node project with
typescript
,@types/node
, andts-node-dev
packages installed.I only get this error when I set
type: "module"
inpackage.json
.ts-node-dev: ^2.0.0
OS version (is it docker or host?), ts-node-dev version
Did you try to run with ts-node?
Did you try to run with
--files
option enabled?Did you try to run with
--debug
option enabled?Do you have a repro example (git repo) with simple steps to reproduce your problem?
The text was updated successfully, but these errors were encountered: