Skip to content
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

Cannot use 1.3.0 with Node.js in ES6 mode - missing type: module in package.json #44

Open
mmomtchev opened this issue Jan 29, 2024 · 2 comments

Comments

@mmomtchev
Copy link

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
@Balearica
Copy link

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.

@SnickerChar
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants