-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[SSR] Vite should use the Node.js built-in resolver instead of using a custom resolver #4447
Comments
Also looks like https://nodejs.org/api/modules.html#modules_require_resolve_request_options is supported by all our supported node versions |
There's a reason Having |
Yes fixing Vite's resolver would be an alternative but I'm concerned that it may take a while until we hunt down all discrepancies between Node.js's resolver and Vite's resolver we are currently experiencing. I don't know wether the two points you mentioned are fundemantal blockers or there are ways to solve/circumvent them but if we can use Node.js's resolver that'd be neat as it would be a bullet-proof solution.
From a high-level perspective, I'm not sure I see an inherent contradiction between using Node.js's
Ok I see. Although I'm wondering: if it's a feature that Node.js doesn't support then how many server-side libraries are using it? E.g. Firebase's server-side library has not been designed with Vite in mind so it certainly doesn't use it. I'm guessing that there aren't that many server-side libraries (I'm guessing only a handful max) using it and it could be worth it to stop supporting the It seems that you and Evan are the most familiar with Vite's current resolve algorithm. Maybe there is a blocker I'm not seeing, but it would be great to be able to simply use Node.js's Thoughts? Looking forward to see Vite evolve into a rock-solid tool :-). |
The existing vite/packages/vite/src/node/utils.ts Line 60 in 7d257c3
I don't see equivalent options in the built-in Node resolver. Is there a way to support that or do we not actually need those options? |
There is https://nodejs.org/api/modules.html#modules_require_extensions but it's deprecated. So I guess we can't use Node.js resolver. |
For bundling server-side code, Vite needs to resolve all SSR dependencies.
Today Vite uses a custom resolver.
I'm proposing to use Node.js's built-in
require.resolve
instead. (Withconst require = createRequire(import.meta.url)
for ESM.)Today, the vast majority of SSR users are using Node.js servers without a server-side bundler. This means that the de-facto standard resolver today is Node.js's built-in resolver.
Maybe Node.js's resolver would even work for bundling browser-side code, since Node.js now supports ESM. But we would need to check whether the Node.js ESM resolver is the same than webpack's ESM resolver. (It should be in principle since ESM is specced.)
But for the server-side, using Node.js's resolver will de-facto work.
@patak I believe there is a plan to use ESBuild to bundle, is this still true?
@aleclarson
I believe we can still support
resolve.dedupe
(we can still dedupe, regardless of how we resolve) andmode
(I'm not sure what is the problem you see here but we can always inject stuff in the bundle, regardless of how we resolve).The text was updated successfully, but these errors were encountered: