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

Bogus sourceType error when using file dependencies #30

Open
nex3 opened this issue Mar 1, 2023 · 0 comments
Open

Bogus sourceType error when using file dependencies #30

nex3 opened this issue Mar 1, 2023 · 0 comments

Comments

@nex3
Copy link

nex3 commented Mar 1, 2023

If I load a chain of modules through a file: dependency, esmify throws a ParseError: 'import' and 'export' may appear only with 'sourceType: module' even when all packages declare it. Here's a repro:

$ echo '{"dependencies": {"subpkg": "file:subpkg"},"sourceType":"module"}' > package.json
$ echo 'import "subpkg";' > test.js
$ mkdir subpkg
$ cd subpkg
$ echo '{"name":"subpkg","dependencies":{"immutable":"^4.2.0"},"sourceType":"module","main":"index.js"}' > package.json
$ echo 'import "immutable";' > index.js
$ npm install
$ cd ..
$ npm install --save-dev browserify esmify
$ npx browserify -p esmify test.js --outfile out.js

This produces:

/home/nweiz/goog/pkg/dart/cli_pkg/browser_library_test/build/npm/node_modules/immutable/dist/immutable.es.js:5950
export default Immutable;
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

It looks like somehow it's loading the "module" entrypoint for immutable.js but not parsing it as a module. Note that immutable.js works fine with browserify if it's not imported from a subpackage, and that the error still appears even after editing its package.json to also contain "sourceType": "module".

Tested with Node v18.12.1, browserify 17.0.0, esmify 2.1.1, immutable 4.2.4

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

1 participant