-
Notifications
You must be signed in to change notification settings - Fork 30k
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
v16.6.0 regression — unexpected error thrown in REPL when calling require() on ES modules in a "type": "module" project #39618
Comments
I can reproduce in the REPL but not in a script : // b.js
require('./a.js') require('./a.js')
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Users\me\workspace\$experiments\nrepo\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///C:/Users/me/workspace/$experiments/nrepo/b.js:1:1
at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)
at async handleMainPromise (node:internal/modules/run_main:63:12) |
This comment has been minimized.
This comment has been minimized.
The error you see with Jest was fixed in #39593 |
Thanks for the link! I searched for issues and PRs before creating this one but missed this fix. That definitely resolves the issue with Jest, all that remains then is the behaviour in the REPL. As it's clear to me now that the issue Jest experienced is distinct from this behaviour in the REPL, I've updated the reproduction instructions and removed the |
git://github.com/creationix/nvm.git |
Version
v16.6.0
Platform
Linux ultima-weapon 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
errors
What steps will reproduce the bug?
package.json
file with"type": "module"
export default {}
or anything else).require()
the file with node REPL.How often does it reproduce? Is there a required condition?
Bug can be consistently reproduced on Node.js 16.6.0.
What is the expected behavior?
An
ERR_REQUIRE_ESM
error is thrown, as it is in 16.5.0 and prior, e.g.:What do you see instead?
An
ERR_INVALID_ARG_TYPE
error is thrown:Additional information
This regression is causing Jest to exit when running on projects withUnrelated to this error; the Jest issue was fixed by #39593 pending release."type": "module"
(see jestjs/jest#11708) since Jest is expecting the ESM error. In that particular case, it looks like Jest actually receives another error — the details are in the linked issue.The text was updated successfully, but these errors were encountered: