-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
CJS imported when ESM export available, then improperly mapped to esm (module.default
became exported_module.default.default
)
#3580
Comments
oh righjt, forgot to mention esbuild version 0.18.13 |
Please follow the issue reporting instructions:
Marking this issue as |
I was hoping the exact version specifiers would be enough context, but if you need an actual example file, I can make a minimal repro project tomorrow |
The entry point from "exports": {
".": {
"bun": "./dist/bun/index.js",
"node": "./dist/cjs/index.js", // <-- choose this one when `import "elysia"`
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js" |
that makes sense, but is there a way to override that for esbuild? also when I was making the reproduction I noticed that the error that appeared before I finished adding all the files indicated that esbuild was trying to look for what's in the also that still leaves out the problem that esbuild bundles the default under (actual reproduction coming in a bit) |
@evanw just do a |
Small update: externalizing
and replacing I'll keep this issue open just in case, but if you look a the repro and see nothing wrong on the esbuild site you can close this issue |
I'm assuming If you believe the author has made a mistake in their package configuration, you are welcome to contact them and try to get it changed. You can also write an esbuild plugin to override esbuild's behavior if you think it's really necessary, although keep in mind that you may be opening yourself up to bugs later on if you do that.
That's because esbuild only looks for the
You may find this helpful: https://esbuild.github.io/content-types/#default-interop. In node, importing the export named I notice all code examples on https://elysiajs.com/ use a named import ( I'm going to close this issue because everything esbuild is doing here seems correct to me. It's respecting the package author's wishes and faithfully replicating the behavior of running the code in node itself. |
thanks for the detailed response, I opened an issue on elysia detailing this issue and a pull request on elysia-logger that replaces the default import with the named one |
In an esm project (type:module in package.json), when bundling
@bogeychan/elysia-logger@0.0.14
, which is an esm-only dependency, withformat=esm
andtarget=node20
theelysia@0.8.5
import gets bundled as (truncated)which lines up with
/elysia/dist/cjs/index.js
as seen on https://www.npmjs.com/package/elysia?activeTab=code, as opposed to/elysia/dist/index.js
that is already availableThis in turn, results in the error "TypeError: import_elysia.default is not a constructor" down the line when trying to execute the bundled equivalent of this code,
which I assume could be related to webpack/webpack#706 (even though that one is a webpack issue), which is supported by the fact that editing
let app3 = new import_elysia.default({
tolet app3 = new import_elysia.default.default({
fixes the issueThe text was updated successfully, but these errors were encountered: