FredKSchott / rollup-plugin-polyfill-node

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

Cannot exclude file #56

Open D4nte opened 2 years ago

D4nte commented 2 years ago

I am getting the following error:

[!] Error: 'setMaxListeners' is not exported by polyfill-node.events.js, imported by node_modules/libp2p/dist/src/peer-routing.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/libp2p/dist/src/peer-routing.js (14:9)
12: // @ts-expect-error module with no types
13:  } from 'set-delayed-interval';
14: import { setMaxListeners } from 'events';
             ^
15: const log = logger('libp2p:peer-routing');
16: export class DefaultPeerRouting {
Error: 'setMaxListeners' is not exported by polyfill-node.events.js, imported by node_modules/libp2p/dist/src/peer-routing.js

In this instance, the events polyfiling is not necessary because the event npm package is used.

Hence I want polyfill to be skipped on the peer-routing.js file.

My rollup config:

import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodePolyfills from "rollup-plugin-polyfill-node";

export default {
  output: {
    file: "dist/bundle.js",
    format: "esm",
    name: "waku",
  },
  plugins: [
    commonjs(),
    json(),
    nodePolyfills({
      exclude: [new RegExp(".*/peer-routing.js")],
    }),
    nodeResolve({
      browser: true,
      preferBuiltins: false,
    }),
  ],
};

I tried:

    nodePolyfills({
      exclude: [new RegExp(".*/peer-routing.js")],
    }),
    nodePolyfills({
      exclude: ["node_modules/libp2p/dist/src/peer-routing.js"],
    }),
    nodePolyfills({
      exclude: [new RegExp("node_modules/libp2p/dist/src/.*")],
    }),

All to no avail, I am still getting the polyfill error.

What am I getting wrong?