You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When it comes to bundling a cjs module into an esm one with some cjs externals, esbuild will convert require to __require and print useful information at runtime. However, it also prevents other ESM based bundlers (rollup, vite (which is using rollup), webpack) including esbuild itself to bundle the esm one again.
For example, in react-dom, there is require("react"), let's bundle it and externalize react:
// no, tsc doesn't do bundle// but if you give it cjs code, it is likely to not change it// inputvarReact=require("react");// outputvarReact=require("react");// not break other bundlers
The text was updated successfully, but these errors were encountered:
hyrious
changed the title
Is there any plan to transform CJS to ESM?
Is there any way to transform CJS to ESM (or keep the require call) ?
Jul 23, 2021
hyrious
changed the title
Is there any way to transform CJS to ESM (or keep the require call) ?
Is there any way to bundle CJS to ESM (or keep the require call) ?
Jul 24, 2021
When it comes to bundling a cjs module into an esm one with some cjs externals, esbuild will convert
require
to__require
and print useful information at runtime. However, it also prevents other ESM based bundlers (rollup, vite (which is using rollup),webpack) including esbuild itself to bundle the esm one again.For example, in react-dom, there is
require("react")
, let's bundle it and externalizereact
:> esbuild index.js --bundle --format=esm --external:react
> rollup index.js -e react -p node-resolve -p commonjs
> tsc --module esnext --target esnext --moduleResolution node
The text was updated successfully, but these errors were encountered: