We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Say we are trying bundle a module write in commonjs:
echo 'module.exports = require("bar").default + 100;' > foo.js esbuild foo.js --bundle --format=esm --external:bar --platform=browser
The format of bar module is ESM and eventually we will made the bar module available in the browser using import-maps like this:
bar
<script type="importmap"> { "imports": { "bar": "https://example.com/bar.js" } } </script>
However, currently esbuild will output something like __require("bar").default, which will cause a runtime error.
__require("bar").default
I guess esbuild is treating bar as a commonjs module, so using __require make sense.
__require
So I wonder if we can specify the external's type, so esbuild will finally generate proper imports for the ESM externals.
If it's in a config file, it should be something like this:
{ externals: ["foo", { name: "bar", type: "esm" }] }
But I'm not sure how it could be done with a CLI argument.
The text was updated successfully, but these errors were encountered:
After some thought, I think what I mentioned in #1927 might be better.
Sorry, something went wrong.
Is this suggestion has any solution? I want to use esm but import some external with commonjs.
No branches or pull requests
Say we are trying bundle a module write in commonjs:
The format of
bar
module is ESM and eventually we will made thebar
module available in the browser using import-maps like this:However, currently esbuild will output something like
__require("bar").default
, which will cause a runtime error.I guess esbuild is treating
bar
as a commonjs module, so using__require
make sense.So I wonder if we can specify the external's type, so esbuild will finally generate proper imports for the ESM externals.
If it's in a config file, it should be something like this:
But I'm not sure how it could be done with a CLI argument.
The text was updated successfully, but these errors were encountered: