SSR can't resolve builtin modules that start with underscore
See original GitHub issueDescribe the bug
Some packages (like @prisma/client
) require the builtin _http_common
module (or others that start with an underscore) which causes ssrLoadModule
to throw Error: Cannot find module '_http_common' imported from ...
error. It seems to be caused by the builtin-modules
package that Vite uses for this purpose filtering out modules that start with an underscore (changing the relevant regex in the transpiled code fixes the problem).
Reproduction
- Clone the repo and install the dependencies: https://github.com/cyco130/vite-ssr-http-common-issue
node ssr-module.mjs
works butnode .
throws trying to load the same module withssrLoadModule
.
System Info
System:
OS: Linux 5.4 Linux Mint 20.2 (Uma)
CPU: (8) x64 Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
Memory: 1.70 GB / 15.53 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.18.1 - /usr/local/bin/node
Yarn: 1.22.11 - ~/.npm-global/bin/yarn
npm: 7.24.1 - ~/.npm-global/bin/npm
Browsers:
Chrome: 96.0.4664.45
Firefox: 94.0
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (7 by maintainers)
Top Results From Across the Web
jshint Error: Cannot find module 'underscore' - Stack Overflow
I can see the /grunt-contrib-jshint directory is in the /node_modules directory. Is there any reason it can't find the underscore module?
Read more >Advanced Features: Custom `Document` - Next.js
A custom Document can update the <html> and <body> tags used to render a Page. This file is only rendered on the server,...
Read more >@sveltejs/adapter-static - npm
Start using @sveltejs/adapter-static in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type ...
Read more >Shared Options | Vite
The default allowed conditions are: import , module , browser , default , and production/development based on current mode. The resolve.conditions config option ......
Read more >Shadow CLJS User's Guide
Embedding in the JS Ecosystem — The :npm-module Target ... shadow-cljs provides several built-in variants that let you get started quickly ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I took a look at why
@prisma/client
is using_http_common
, looks like it’s used by a dependency called https://github.com/nodejs/undici. From this comment, undici v4 should remove the need for_http_common
, so all that’s left is for@prisma/client
to upgrade to v4, which is not done yet (https://github.com/prisma/prisma/issues/7539). Maybe it’s better to wait for the PR in the long term?@Niputi No, I tested the above reproduction repo with
vite@2.6.14
and got the same error. It is a bug of vite all the time, @bluwy is right.In addition, I fetched your PR code and re-tested, it has solved the bug. 👍