Open elrumordelaluz opened 2 years ago
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:
import { sassPlugin } from 'esbuild-sass-plugin';
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['src/index.ts'],
sourcemap: true,
clean: true,
bundle: true,
dts: true,
esbuildPlugins: [sassPlugin()],
splitting: true,
minify: true,
format: ['esm', 'cjs'],
external: ['react', 'react-dom']
});
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);`,
};
}
},
});
Or maybe even as part of the shims
option...
@egoist
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