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

npm i esbuild --no-optional is missing node_modules/.bin/esbuild #2558

Closed
evanw opened this issue Sep 19, 2022 · 0 comments
Closed

npm i esbuild --no-optional is missing node_modules/.bin/esbuild #2558

evanw opened this issue Sep 19, 2022 · 0 comments

Comments

@evanw
Copy link
Owner

evanw commented Sep 19, 2022

It looks like npm's .bin folder is broken by design: npm/cli#3905. Nested dependencies with executables can clobber executables with the same name in parent dependencies, and no attempt is made by npm to avoid this. Whatever the executable ends up being is non-deterministic and random. It doesn't sound like this bug will ever be fixed.

In esbuild's case, I was trying to reuse the esbuild-wasm package in some of esbuild's optional dependencies. So esbuild optionally depends on @esbuild/android-arm which depends on esbuild-wasm. But if you specify --no-optional when you install esbuild (so the nested esbuild-wasm dependency could not possibly be installed on any platform), the esbuild executable from esbuild-wasm causes the node_modules/.bin/esbuild symlink to be erased.

This is due to npm's _addOmitsToTrashList function here. The esbuild-wasm package and the esbuild package deliberately both have an executable named esbuild (specifically in the "bin" field of their package.json files) so that you can substitute the esbuild-wasm package for the esbuild package and your install scripts will still work.

One workaround could be to go back to sticking a full copy of the WASM blob into every shim package. Another workaround could be to publish a second WASM package that's identical to the first but that doesn't have a "bin" field in its package.json file.

@evanw evanw closed this as completed in 758d4e1 Sep 22, 2022
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