-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Module "events" has been externalized for browser compatibility #9238
Comments
Would you provide a minimal repro, not the entire project? |
Hello @sgnilreutr. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
@sapphi-red initial post has been updated. |
Previously Vite 2 was wrongly handling this. |
@sapphi-red does this also apply for the error I'm having about I'm getting the same issue using Intertia + Laravel vite plugin:
More details can be found here: laravel/vite-plugin#102 |
@sebsobseb That one is a bug. |
@sapphi-red ok, thanks for confirming. |
@sebsobseb #7599 won't be merged because it only explains the reason of the bug. #9170 might fix this but I've not checked yet. |
@sapphi-red Ok, fair enough, appreciate the help. Simply importing With the plugin (on my machine) this throws the following error in the console:
Do you reckon it could be because of the plugin or because of my machine? This is what the config of the plugin looks like: The other difference is that i'm using Yarn 3.2.1, in stackblitz it's v1.22. |
✅ The issue disappeared when I switched from Yarn to NPM 🤷♂️ |
@sebsobseb Umm. Does it reproduce if you import inertia.js instead of directly importing |
Yeah, the issue seems to be related pnp mode only. I switched to yarn's node-modules linker and the problem is gone. |
@sapphi-red I've tried adding the 'events' package (https://www.npmjs.com/package/events), but then I run into a similar issue: I've also tried installing 'rollup-plugin-node-polyfills' (https://www.npmjs.com/package/rollup-plugin-node-polyfills) and setting it in vite.config.js
So then I add this to vite.config.js:
Then I found this post https://stackoverflow.com/a/70666018/3017716 and added those things to the vite.config.js. It seems to be working now... |
The StackOverflow answer mentioned above also worked for me... |
Fighting with the polypill nightmare. Anyone is able to fix the issue with Sveltekit/vite? This is the config I'm using (process and buffer are not warning anymore so I guess it's "working" but I'm stuck on events)
|
See that link on Stack Overflow, you need to use a 'resolve' block and specifically map the 'events' import to a file on that polyfill. Also, there is a newer version of the polyfill:
https://github.com/FredKSchott/rollup-plugin-polyfill-node
Look in the 'polyfills' directory and you will see all of the node modules that you can alias.
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Lionel ***@***.***>
Sent: Saturday, August 6, 2022 12:06:31 PM
To: vitejs/vite ***@***.***>
Cc: justin0mcateer ***@***.***>; Comment ***@***.***>
Subject: Re: [vitejs/vite] Error: Module "events" has been externalized for browser compatibility (Issue #9238)
Fighting with the polypill nightmare. Anyone is able to fix the issue with Sveltekit/vite?
This is the config I'm using (process and buffer are not warning anymore so I guess it's "working" but I'm stuck on events)
import nodePolyfills from "rollup-plugin-polyfill-node";
import { defineConfig } from "vite";
import { svelte } from ***@***.***/vite-plugin-svelte";
export default defineConfig({
plugins: [nodePolyfills({ include: null }), svelte()],
});
—
Reply to this email directly, view it on GitHub<#9238 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAT4Q7I67SHOSWK57EZTYY3VX2LRPANCNFSM54CD2BLA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Ah man, thanks a lot! I tried that initially and got some weird errors with string_encoder but it turns out it's not necessary. Do you know if it has an impact to add all the polyfills (so we could always use the same config file in different projects) or is it best to only add the ones needed? |
My thought was to minimize the aliases. Overtime, I plan to try to eliminate these with different deps or upstream patches.
I did run into a problem with one polyfill depending on a different one (process) and it wasn't referenced, so it wasn't resolving. I had to add an import to get it to work correctly.
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Lionel ***@***.***>
Sent: Sunday, August 7, 2022 3:12:45 AM
To: vitejs/vite ***@***.***>
Cc: justin0mcateer ***@***.***>; Comment ***@***.***>
Subject: Re: [vitejs/vite] Error: Module "events" has been externalized for browser compatibility (Issue #9238)
Ah man, thanks a lot! I tried that initially and got some weird errors with string_encoder but it turns out it's not necessary.
Do you know if it has an impact to add all the polyfills (so we could always use the same config file in different projects) or is it best to only add the ones needed?
—
Reply to this email directly, view it on GitHub<#9238 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAT4Q7MS5GPNNBIUK5XMYVTVX5VX3ANCNFSM54CD2BLA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Describe the bug
After upgrading to Vite 3.0.2 (since 2.X version has some production level bugs for me) - the production version started working, but the development is crashing due to the following error:
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
After removing the mentioned dependency 'HtmlParser' -> https://www.npmjs.com/package/react-html-parser -> the installation seems to work.
Reproduction
https://stackblitz.com/edit/react-rj6cc2
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: