Cannot use 1.3.0 with Node.js in ES6 mode - missing `type: module` in `package.json`
mmomtchev opened this issue · comments
package.json
:
{
"type": "module",
"dependencies": {
"web-worker": "^1.3.0"
}
}
test.js
:
import WebWorker from 'web-worker';
node test.js
:
(node:18927) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/mmom/src/tmp/node_modules/web-worker/node.js:17
import URL from 'url';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1274:20)
at Module._compile (node:internal/modules/cjs/loader:1320:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
at Module.load (node:internal/modules/cjs/loader:1197:32)
at Module._load (node:internal/modules/cjs/loader:1013:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:202:29)
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
at async loadESM (node:internal/process/esm_loader:34:7)
Node.js v18.19.0
Also experienced this. It's unclear to me whether this is a bug in 1.3.0 or a purposeful change, however if the latter is true then this should have been a new major version. The 1.3.0
release breaks projects that pinned earlier 1.x
releases in package.json
, which should not happen.
For what it's worth, I fixed this by adding "web-worker": "1.2.0" to the resolutions
section in my package.json. The changes for 1.3.0 are pretty minor, the changes made to the package.json in that version to try and make the cross-module support smarter is what screwed up.