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.

Error: Module "module" has been externalized for browser compatibility

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
sgnilreutrcommented, Jul 19, 2022

@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

1reaction
patak-devcommented, Jul 21, 2022

That issue is closed, if you think that the comment from @sapphi-red isn’t right please comment there.

Read more comments on GitHub >

github_iconTop 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 >

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