-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: apply SSR externalization heuristic to devDependencies #4699
Conversation
Sorry for the failing test, seems it's a main branch error from last commit |
Looks like this was the original intent, as far as I could track it https://github.com/vitejs/vite/blame/b813b00d234ecb500ae688c4da2b11d3c7a3070b/packages/vite/src/node/ssrExternal.ts#L16 I'm a bit confused here. Shouldn't these helpers be in dependencies instead of devDependencies if they are going to be needed during SSR? |
Why would that be the case? When I use Rollup, stuff in |
@patak-js Thanks for the ping. I'm very much interested in that area. AFAICT the only one who knows the rationale about the externalize heuristic is Evan. I think we should cue him in at some point in the discussion. I'm going to repeat myself but I really can't see any reason why we don't externalize everything by default. AFAICT there is no need for a heuristic here. It seems to me that the contributor community thinks that the sole purpose of the externalize heursitic is ESM/CJS compatibility (correct me if I'm wrong; I didn't read some of the Discord discussions). But, for ESM/CJS handling, I believe (I'm actually pretty confident here) that following will do the trick:
That's it. There is no need to transpile dependencies to make ESM/CJS work. Note that I had 0 users complaining about server dependency problems with Isomorphic and browser-side dependencies are designed to work with bundlers. Whereas server dependencies are designed to work with Node.js (they actually often don't work with bundlers). That's a fundamental reason why we should externalize everything by default. So the fundamental underlying question behind this PR is: do we want to externalize everything by default? It would be great to make progress on that decision. From my perspective, this is the biggest change we can make to make SSR rock-solid. |
I largely agree with you @brillout. But that's a bigger change and I don't want to get too off-topic on this or block other improvements to the existing SSR system in the meantime. There's a basic question here, which is should |
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.
I agree that SSR externalization needs a major overhaul later.
But this incremental change looks good to me. It's not likely to break existing use cases and solves a real problem.
I don't see the rationale for treating
Makes sense — I just approved the PR. It's nice that we agree to discuss the externalize heursitic from the ground up. @patak-js How should we proceed? I can open a new GitHub ticket |
Btw. one downside of this PR is that it could considerably slow down things. Deps like |
|
I think this would be very useful. Evan is going to be looking into SSR soon IIUC so this should help him navigate what was discussed so far. I think it is a good idea to show your proposal but also document fairly other points of view you saw at least with links to the comments/PRs (I think there were some open PRs from Alec for example). I think that it was good to keep SSR experimental so if there are API changes, we are still on time to do them now that the ecosystem is also small enough to coordinate |
Description
Use the SSR externalization heuristic for
devDependencies
just like we do fordependencies
. Whether something is independencies
vsdevDependencies
doesn't say anything about whether it might be written in CJS or ESM. It's also an undocumented behavior to treatdependencies
vsdevDependencies
differently so is a bit confusing in that regardAdditional context
SvelteKit's helper libraries don't work because they're distributed as ESM (sveltejs/kit#2237). Since Vite assumes they can always be externalized and loaded with
require
Vite fails to import themWhat is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).