Error: Module "module" has been externalized for browser compatibility
See original GitHub issueDescribe the bug
At Qwik, we use Vite. When updating to 3.0.0, we found out that the app always crashes in the browser, because a SSR module leaks and it’s imported through a ESM import in the browser code.
Internally QwikVite plugin uses ssrLoadModule(). seems like it’s caching the transform needed for SSR and making it accessible from the client, when hitting the URL.
even manually setting transformRequest(url, {ssr: false])
returns a request that in SSR only.
This was not a problem in 2.9.9
Uncaught (in promise) Error: Module "module" has been externalized for browser compatibility. Cannot access "module.createRequire" in client code.
at Object.get (__vite-browser-external:module:3:11)
at @builder__io_qwik.js?v=594c8cff:1:192
Reproduction
https://stackblitz.com/edit/nextjs-opbbv2?file=README.md,src%2Froutes%2Findex.tsx,vite.config.ts
System Info
System:
OS: macOS 12.4
CPU: (10) arm64 Apple M1 Pro
Memory: 425.98 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
Yarn: 3.2.0 - ~/.yarn/bin/yarn
npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
Browsers:
Chrome: 103.0.5060.114
Safari: 15.5
npmPackages:
vite: 3.0.0 => 3.0.0
Used Package Manager
yarn
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 vuejs/core 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 a year ago
- Reactions:2
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Module "http" has been externalized for browser compatibility ...
I have now spent many hours trying to understand how to polyfill/shim the dependencies in Vite, but I'm quite stuck. I get this...
Read more >Module "path" has been externalized for browser compatibility
Module "path" has been externalized for browser compatibility and cannot be accessed in client code. Solution. Steps: Install "path-browserify":.
Read more >Uncaught Error: Module "events" has been externalized for ...
Error : Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code. git repo link : ...
Read more >module fs has been externalized for browser compatibility.
Uncaught Error: Module "fs" has been externalized for browser compatibility and cannot be accessed in client code. at Object.get (browser-external:fs:3:11) ...
Read more >vite-plugin-node-polyfills - NPM Package Overview - Socket.dev
Module "stream" has been externalized for browser compatibility. Cannot access "stream.Readable" in client code.
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
@patak-dev unfortunately similar bugs are still there:
Uncaught Error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code. get events:9 js Parser.js:133 __require chunk-QOVRSCHT.js:11 js index.js:1 __require chunk-QOVRSCHT.js:11 <anonymous> HtmlParser.js:1 [events:9:12](browser-external:events) get events:9 js Parser.js:133 __require chunk-QOVRSCHT.js:11 js index.js:1 __require chunk-QOVRSCHT.js:11 <anonymous> HtmlParser.js:1 InnerModuleEvaluation self-hosted:2361 InnerModuleEvaluation self-hosted:2361 InnerModuleEvaluation self-hosted:2361 InnerModuleEvaluation self-hosted:2361 InnerModuleEvaluation self-hosted:2361 InnerModuleEvaluation self-hosted:2361 evaluation self-hosted:2322
That issue is closed, if you think that the comment from @sapphi-red isn’t right please comment there.