-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 [ERR_REQUIRE_ESM] #1129
Comments
Same problem |
Inquirer v9 is an esm node module. So TypeScript code must be compiled to ESM too for Node to work properly. See release announcement #1126 and feel free to discuss over there your solution or ask for help. This is not a bug with Inquirer. A few resources that might help you find the right configuration:
Also, bundling your dependencies in a single package with babel/webpack/etc should also interop properly. |
This basically means we can't use Inquirer with ts-node while development. |
@softmarshmallow that isn't true. I've been using ts-node while developing inquirer itself. You need to add this to your Also, as long as you bundle all the code together, you can compile in any way you wants. The problem with modules for npm is if your module is compiled to commonjs, but relies on esm dependencies. |
@SBoudrias what is the recommended way to use Inquirer for commonjs project? Just use v8? |
@bali182 yeah, that's your best bet for now! |
I still get |
@SBoudrias Unless you use Typescript Paths (https://www.typescriptlang.org/tsconfig#paths) like import from @core/myModule So stuck working with the outdated version. |
Explanation of the problem.The error "[ERR_REQUIRE_ESM]: require() of ES Module not supported. Instead change the require of index.js to a dynamic import() which is available in all CommonJS modules" occurs because a package you are importing has been converted to an First solution
Second solution
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
/* ... your props ... */
},
"ts-node": {
"esm": true
}
}
//Bad
import { random } from './utils'
//Good
import { random } from './utils.js' With this the error has to be solved. If you found another way to solve the problem, you can reply to this comment to help others. 🫶 |
The second option partially works for me. While the import of inquirer.js now works, literally all of the other regular imports in the rest of the code have stopped working. |
You are absolutely right, due to the change that was added with the second option, it is necessary that you add the For example: // Bad
import { random } from './utils'
// Good
import { random } from './utils.js' I hope this works for you. |
fallback to version 8 fix the problem |
|
Confirmed. Fixed my issue too. |
Error detail as bellow:
code
Env:
Node version v16.11.1
tsconfig:
script in package.json
The text was updated successfully, but these errors were encountered: