FredKSchott / FredKSchott/rollup-plugin-polyfill-node

Cannot exclude file

Open
#56 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
193
Forks
60
PR merge metrics
No merged PRs in 30d

Description

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:

```js
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.