-
Notifications
You must be signed in to change notification settings - Fork 82
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
How to ship in CJS format when my package has pure ESM package dependencies? #79
Comments
Hey, same question. My case was with |
Thanks for the idea, I want to ship both |
When possible, using dynamic imports is the best way to load such libraries for CJS build support: const execa = await import('execa') Unbuild has rollup.inlineDependencies option that inlines all deps but i would avoid that. But i would go with dynamic import as possible. Some alternatives:
|
In my context I can't not ship CJS unfortunately. I could downgrade That being said @pi0, I was using the following config which did not inline export default defineBuildConfig({
entries: [
'src/index',
'src/inertia',
],
clean: true,
declaration: true,
externals: [
'rollup',
'vite',
'esbuild',
'tailwindcss',
'autoprefixer',
],
rollup: {
emitCJS: true,
inlineDependencies: true,
},
}) I use |
Do you mind to share a repo @innocenzi? Also certainly you cannot use dynamic import approach? Being able to inline is for sure a valid case but it is not always the best idea... |
Sure @pi0: https://github.com/innocenzi/unbuild-issue-79 Run In my case the dynamic import is not an option, but I can downgrade |
Anthony Fu helped me, I just needed to make So @holazz to solve the issue, use Alternatively, as @pi0 said, find the same lib exported as CJS ( Hopefully this solves the issue for anyone stumbling upon it. |
Thank You Kindly! |
index.ts:
build.config.ts:
run
unbuild && node dist/index.cjs
and get error:The text was updated successfully, but these errors were encountered: