Skip to content

Instantly share code, notes, and snippets.

@thecodermehedi
Last active April 10, 2025 07:02
Show Gist options
  • Save thecodermehedi/adc7955d948f6f7531732d42b233661f to your computer and use it in GitHub Desktop.
Save thecodermehedi/adc7955d948f6f7531732d42b233661f to your computer and use it in GitHub Desktop.
browser-external:events:9 Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

Problem

browser-external:events:9 Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

Solution:

i used this package to fix the problem: vite-plugin-node-polyfills

pnpm install --save-dev vite-plugin-node-polyfills

Usage

in your vite.config.js file

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { nodePolyfills } from "vite-plugin-node-polyfills";

export default defineConfig({
  plugins: [react(), nodePolyfills()],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment