Uncaught Error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code
Asked Answered
C

5

6

I don't know what's going on I am making a frontend using vite + react for my mern project and suddenly starts encountering this error.

Error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code.

git repo link : https://github.com/Gaurav200247/E-Book-Store-Mern-Project

Catchings answered 1/8, 2022 at 9:29 Comment(2)
Hi! Could you figure it out? I'm stuck with the same issue.Quack
not able to figure it out, but i'm using localstorage (JS) in my code i just removed that lines of code. The error gone automatically.Catchings
S
6

Had the same issue, the events module was in sub-dependencies, I added it manually by npm install events, then the issue disappeared.

Silkworm answered 10/8, 2022 at 19:17 Comment(3)
Did you import anything afterwards?Samuelsamuela
No, it couldn't find that module somewhere inside of a dependency. After manual installation that becomes available.Silkworm
for me error is not resolved even after installing events , with npm i eventsGlume
S
2

Make sure that:

  1. You are importing the correct library in your code.
  2. The library you are attempting to use is directly installed in your project, libraries available as sub-dependencies will not work.
Suzy answered 28/9, 2022 at 23:6 Comment(0)
B
0

it happens when mistakenly a backend package gets imported in frontend

Blush answered 23/9, 2023 at 4:12 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Ikeda
T
0

I have faced this problem when I have installed jsonwebtoken in client side. You need to avoid install server side packages or modules in client side to avoid this error or warning.

Tomkin answered 26/5 at 17:39 Comment(0)
G
0

In case you are using Angular and stumble upon this page, know that the other solutions are temporary. This might be an issue caused by the auto importing of the package by IDE, say vsCode.

The other solutions mention just installing the package. However, what you need to check is if you're importing the eventEmitter from the right library.

Check that it is

import { EventEmitter } from '@angular/core';

and NOT

import { EventEmitter } from 'stream';

The other solutions mention running npm i or installing the package, but in turn, you are just installing the stream package, which is probably not needed.

Gersham answered 2/8 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.