-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Using --external:./node_modules/* results in relative import instead of bare import #1958
Comments
I just stumbled into this as well. This causes npx to be broken though as the node_modules folder is not created in the same location after 'install'. |
Fixed to exluding externals explicitely Note previously used node_modules/* based on documentation but that rewrite to relative paths which do not follow node module resolution rules. evanw/esbuild#1958
I've also encountered this issue while trying to use esbuild to bundle some TS code for an Electron application. |
Hi, I run into this as well. This only happens for |
i'm also running into this with juliencrn/usehooks-ts#97 |
This reverts commit c678f84. trigger pulled too soon: - evanw/esbuild#619 was gone - but then come evanw/esbuild#1958
Not sure if you've already considered it, but this would be a great breaking change to include in something like #2508. I've personally worked around this by doing something like EDIT: Don't do the above... Just do |
I think that this is the same bug, but one thing I've noticed is that if you set chai = __toESM(require("../../node_modules/chai/index.mjs")); Which will fail to work since that's not CJS code. If the code had not been external, this would have been fine since it'd be bundled and so the MJS-ness of the file would not matter. Setting the conditions to be |
After viewing some of the cross-linked PRs, I realized that I had completely glossed over the fact that you can just specify each package name as "external" directly, rather than using a wildcard. With that in mind, I've ended up going with using a plugin that enforces that "external" is fully configured: {
name: "no-node-modules",
setup: (build) => {
build.onLoad({ filter: /[\\/]node_modules[\\/]/ }, () => {
// See: https://github.com/evanw/esbuild/issues/1958
return {
errors: [{ text: 'Attempted to bundle from node_modules; ensure "external" is set correctly.' }]
};
});
}
}, This gives me a handy error at bundle time: This is plenty for my needs. |
Signed-off-by: António Meireles <antonio.meireles@reformi.st>
From
entry.js
:Run build:
esbuild entry.js --bundle --outfile=out.js --format=esm --external:"./node_modules/*"
Then
out.js
:But if I just exclude
react
directly:Then the result will be:
Or if I use the plugin below to manually exclude all packages from
node_modules
. The result will still be a bare import.Originally posted by @evanw in #619 (comment)
So I'm not sure if this is the intended behavior or bug?. And if this is intended, how can I do this without using a plugin?
Thank you.
The text was updated successfully, but these errors were encountered: