-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
esbuild@>=0.14.5 introduces a regression for __toESM(require('esbuild')) #1897
Comments
This is because there's no export called
|
Yes, esbuild does not have a default export. But the job of __toESM is to add a .default in case the module does not have one? If so, import_esbuild.default should not be undefined. Am I wrong? |
esbuild is aligned to the babel/webpack behavior of es module interop since 0.14.5. That is to say, if a cjs file has In fact, node's behavior is getting more complex during the days. In node.js 17, importing a cjs module will give you not only the whole In conclusion, esbuild (and other bundlers) will be consist with their esm interop rule when transforming esm to cjs. If you want to get the node.js behavior, why not just output esm (format: esm) and let node run that? |
This is incorrect. The job of __toESM is to implement esbuild's ESM interop behavior. That behavior only involves overwriting the default export when the file is in node compatibility mode. Node compatibility mode is only enabled if the file extension is |
Thanks both of you. It must bo clear that typescript's esModuleInterop cannot be used with esbuild. Because typescript will add the .default if the module does not defined a default, but esbuild will not (but code will compile and type check successfully). Is this something "normal" or a warn should be throwned? |
TypeScript doesn't add .default if |
Okay!! I was missing the Shouldn't this version (0.14.5) have been a breaking change then? |
Perhaps. Technically every version is a breaking change for people relying on the old behavior. It's up to the publisher what is considered "bug fix" vs. "breaking change" even though bug fixes can break code that makes use of the bug. It seemed like a bug fix to me (specifically #1719, #1591, and #532). |
I would say, only in the case where the old behavior was not the good one. If in the first place, le old behavior was just a mistake in the implementation, then it is a breaking. But if the old behavior should have worked like the new one, then it is a bug. |
Currently experiencing this with "styled-components" too, which as a popular library, I suspect a lot of people have the same issue? upvote if you do, or I made a mistake on my end. Setup:
Im using tsup to bundle the library, thus im here. |
Repro repository - use-tsup branch
git checkout f336527bb964c0933a25168b821f334bd52c7a55
pnpm i
cd packages/ee
-pnpm prepublishOnly
cd ../electron-esbuild
-pnpm prepublishOnly
Used command to build
ee
package :esbuild src/index.ts --outdir=dist --bundle --platform=node --external:esbuild --sourcemap
. Noteesbuild
as externalCURRENT:
Uncaught TypeError: Cannot read properties of undefined (reading 'build')
EXPECTED:
no error
This is working with esbuild 0.14.3, redo all above with
cd packages/ee
-pnpm i -D esbuild@0.14.3
The problem is that esbuild changes the source from
to
But from esbuild@0.14.5,
var import_esbuild = __toESM(require('esbuild')).default
is undefined but not withesbuild@<0.14.5
Note that, this is working using
import { build } from 'esbuild'
because bundled source do not useimport_esbuild.default.build
butimport_esbuild.build
directlyThe text was updated successfully, but these errors were encountered: