-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix(vercel): CJS bundle fix #3051
Conversation
🦋 Changeset detectedLatest commit: 76349ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Thanks Juan! I don't feel confident enough to review this one, so leaving for @matthewp to take a look when he gets back on Tuesday! |
This doesn't look like a Vercel-specific issue. This would happen during the static build. The cause is this:
I can see a couple of possible solutions here:
If this is going to be a common problem then we might want to do (1). Maybe there are other solutions I'm not thinking about? |
I'm aware of that, it was some mismatch when doing ESM -> CJS. Since this integration is the only one doing it, I made a quick fix.
I added the bundling of dependencies because I can't get Vercel's Node File Tracing working. But yes, the first options seems like a good idea. How can I do that? |
I don't think there's a way to control this at the moment. There's this option https://vitejs.dev/config/#resolve-mainfields but it doesn't work in SSR currently. I think the workaround for your own projects is to use Going to close this as we don't want to force CJS on everyone. Can continue discussing a general solution. |
I don't know why this was closed. There was an error when Rollup generated a bundle in ESM and then esbuild converted to CJS because Vercel needs it. This PR makes Rollup generate CJS from the go and then uses esbuild to bundle the dependencies, which worked well for me. The ideal case is not to bundle any dependency and having an
This isn't forcing CJS on everyone, right? Only the people who has the Vercel adapter will have their output in CJS (mainly because Vercel doesn't support ESM) |
Do you have any links about Vercel not supporting ESM? I couldn't find anything when I searched. My hesitancy about this issue is a couple of things:
However, if Vercel really doesn't support ESM at all then that changes things a bit. |
@matthewp yeah, it isn't documented because they transpile from ESM to CJS internally anything inside a
Vercel once supported it, but they reverted it because it caused some errors. You can see the PRs related to tue upgrading of |
I totally agree with you, but Vercel and Next.js do that anyways. SvelteKit only does it with the Vercel adapter and the in-development |
Ok, let's reopen and continue the discussion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for your patience and for explaining everything @JuanM04!
Changes
This fixes some issues when converting from ESM to CJS.
Testing
Docs