question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[SSR] Vite should use the Node.js built-in resolver instead of using a custom resolver

See original GitHub issue

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. (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?

@aleclarson

It’s not really an issue if Vite handles it properly. Besides, that would prevent resolve.dedupe and mode 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Shinigami92commented, Jul 30, 2021

Also looks like https://nodejs.org/api/modules.html#modules_require_resolve_request_options is supported by all our supported node versions

0reactions
brilloutcommented, Oct 1, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SSR] Stop resolving externalized dependencies #4340 - GitHub
(I.e. Vite uses it's owner node resolver instead of using Node.js' built-in require / require.resolve .) Vite doing dep resolving is the root ......
Read more >
Server-Side Rendering - Vite
Vite provides built-in support for server-side rendering (SSR). The Vite playground contains example SSR setups for Vue 3 and React, which can be...
Read more >
Features | Vite
Vite uses esbuild to transpile TypeScript into JavaScript which is about 20~30x faster than vanilla tsc , and HMR updates can reflect in...
Read more >
Shared Options | Vite
More advanced custom resolution can be achieved through plugins. If you have configured aliases for SSR externalized dependencies, you may want to alias...
Read more >
Configuring Vite
When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found