-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
ESM output with CJS content #701
Comments
Related: |
The solution is to external the other cjs packages that required react, like react-dom |
hey could you solve this? I'm using external react and still got the same error |
any update on this guys? tsup version: 8.0.1 I am using following tsup config:
but in App after npm install I am getting an error (index.js:1 Uncaught Error: Dynamic require of "react" is not supported) |
@egoist I wonder if you might want to include the workaround that some other bundlers use, but esbuild doesn't, as a plugin in tsup: import { defineConfig } from 'tsup';
export default defineConfig({
// *snip*
banner(ctx) {
if (ctx.format === "esm") {
return {
js: `import { createRequire } from 'module'; const require = createRequire(import.meta.url);`,
};
}
},
}); |
in tsup configuration, we have ad-hoc banner insertion for require. this solution is taken from egoist/tsup#701 (comment)
Or maybe even as part of the |
I am pretty happy using
tsup
for a couple of packages inside a monorepo (usingturbo
), but having several problems with a particular one, which fires the error described at #579, in my case, the message is:The
dev
andbuild
scripts are the same for all packages, however I am noticing that for this particular one, the.mjs
and.js
output is pretty similar. I mean that themjs
file has the appearance to be transpiled into cjs, like in the screenshot below, when in the other packages, the same file maintains theimport
statements and modern structure like the input file.Thanks in advance!
Upvote & Fund
The text was updated successfully, but these errors were encountered: