[SSR] Vite should use the Node.js built-in resolver instead of using a custom resolver
See original GitHub issueFor 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. (With const 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?
It’s not really an issue if Vite handles it properly. Besides, that would prevent
resolve.dedupe
andmode
from affecting module resolution in SSR, which isn’t preferable.
I believe we can still support resolve.dedupe
(we can still dedupe, regardless of how we resolve) and mode
(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).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (4 by maintainers)
Also looks like https://nodejs.org/api/modules.html#modules_require_resolve_request_options is supported by all our supported node versions
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.