Skip to content
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

Use ESM for SSR builds #8150

Closed
4 tasks done
benmccann opened this issue May 12, 2022 · 3 comments · Fixed by #8348
Closed
4 tasks done

Use ESM for SSR builds #8150

benmccann opened this issue May 12, 2022 · 3 comments · Fixed by #8348
Labels
enhancement New feature or request feat: ssr p3-significant High priority enhancement (priority)
Milestone

Comments

@benmccann
Copy link
Collaborator

Clear and concise description of the problem

Vite currently builds SSR code as CJS.

I think that is controlled here:

format: 'cjs',

Suggested solution

ESM is the future, so it would be nice to make it the default. SvelteKit, Astro, Nuxt, vite-plugin-ssr, Hydrogen, and Vitedge are all using ESM already, so it's possible we could stop supporting CJS altogether

Alternative

We could keep CJS around as an option for 3.0 and then drop it in 4.0. There are only a couple known issues and they're both being worked on. It's unclear if they'd be blockers

Additional context

This was originally suggested here: #8033 (comment)

Validations

@bluwy
Copy link
Member

bluwy commented May 13, 2022

Maybe #6812 would cover this too, but the PR is stale.

@patak-dev patak-dev added enhancement New feature or request p3-significant High priority enhancement (priority) and removed enhancement: pending triage labels May 26, 2022
@aleclarson
Copy link
Member

I don't really see the point in dropping CJS support. Why not let people do what they want?

@patak-dev
Copy link
Member

I don't really see the point in dropping CJS support. Why not let people do what they want?

We haven't decided to drop support for CJS in v3 yet. I think it isn't going to be possible at this point. Maybe there is an intermediate option where we keep it as deprecated with a note of intent that is going to be removed in 6 months or so, or it will be kept but not maintained. Only as a way to give people an easier migration path to Vite v3.
Regarding why we may want to drop support for CJS SSR builds, they currently require the esbuild scanner and the previous externalization logic heuristics. We have cleaned this for the ESM builds, but IIUC we can't do the same for CJS. I think a third option would be to also switch the CJS SSR build to externalization by default, and if users want to use it, they'll have to deal with noExternal themselves.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: ssr p3-significant High priority enhancement (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants