FredKSchott / rollup-plugin-polyfill-node

A modern Node.js polyfill for your Rollup bundle.
Other
175 stars 55 forks source link

Uncaught SyntaxError: The requested module 'events.js' does not provide an export named 'default' #37

Closed faustbrian closed 2 years ago

faustbrian commented 2 years ago

When using this package with vite I'm running into the error Uncaught SyntaxError: The requested module '/node_modules/.pnpm/events@3.3.0/node_modules/events/events.js?v=be595b23' does not provide an export named 'default' when opening the project in a browser.

Screenshot 2021-12-09 at 4 51 07
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
import svgrPlugin from "vite-plugin-svgr";
import macrosPlugin from "vite-plugin-babel-macros";
import polyfillNode from "rollup-plugin-polyfill-node";

// https://vitejs.dev/config/
export default defineConfig({
    build: {
        target: "esnext",
    },
    define: {
        "process.env": process.env,
    },
    plugins: [
        react(),
        tsconfigPaths(),
        svgrPlugin(),
        macrosPlugin(),
        polyfillNode(),
    ],
    optimizeDeps: {
        exclude: [
            "@ledgerhq/hw-transport-webusb",
        ],
    },
});

Any idea what could cause this? Does the polyfill not exactly mirror how node.js exports the events module?

faustbrian commented 2 years ago

@FredKSchott @quolpr could this be related to https://github.com/FredKSchott/rollup-plugin-polyfill-node/issues/22?

simonhaenisch commented 2 years ago

See https://github.com/FredKSchott/rollup-plugin-polyfill-node/issues/22#issuecomment-995580606 for a work-around.

FredKSchott commented 2 years ago

would love any help if our events polyfill needs a fix!

FredKSchott commented 2 years ago

Fixed by https://github.com/FredKSchott/rollup-plugin-polyfill-node/pull/42