waku-org / js-waku

JavaScript implementation of Waku v2
https://js.waku.org
Apache License 2.0
167 stars 42 forks source link

Upgrading from 0.0.16 to 0.0.18 breaks build #1564

Closed agazso closed 11 months ago

agazso commented 1 year ago

This is a bug report

Problem

I have an application that uses @waku/sdk. I tried upgrading the version of @waku/sdk from 0.0.16 to 0.0.18 and changed nothing else and now my build is failing (see the error output at the end).

It looks like a polyfill issue again coming from libp2p.

Notes

@waku/sdk version 0.0.18 (the latest working that I tried was 0.0.16) Node.js v18.17.1 on Linux

Error output when building:

vite v4.3.9 building for production...
transforming (696) node_modules/.pnpm/uint8arrays@4.0.6/node_modules/uint8arrays/dist/src/from-string.js[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/ping/index.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
transforming (774) node_modules/.pnpm/@waku+proto@0.0.5/node_modules/@waku/proto/dist/index.js[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/identify/identify.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
transforming (831) node_modules/.pnpm/@multiformats+mafmt@12.1.3/node_modules/@multiformats/mafmt/dist/src/index.js[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/libp2p.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
transforming (878) node_modules/.pnpm/@chainsafe+libp2p-gossipsub@9.1.0/node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/decodeRpc.js[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/upgrader.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
transforming (1001) node_modules/.pnpm/@chainsafe+libp2p-noise@12.0.2/node_modules/@chainsafe/libp2p-noise/dist/src/handshakes/xx.js[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/connection-manager/dial-queue.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
transforming (1122) node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/_u64.js[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/connection-manager/utils.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
transforming (1382) src/lib/objects/external/lib.tsnode_modules/.pnpm/@protobufjs+inquire@1.1.0/node_modules/@protobufjs/inquire/index.js (12:18) Use of eval in "node_modules/.pnpm/@protobufjs+inquire@1.1.0/node_modules/@protobufjs/inquire/index.js" is strongly discouraged as it poses security risks and may cause issues with minification.
✓ 1384 modules transformed.
✓ built in 5.87s
"setMaxListeners" is not exported by "__vite-browser-external", imported by "node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/connection-manager/utils.js".
file: /home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/connection-manager/utils.js:1:9
1: import { setMaxListeners } from 'events';
            ^
2: import { logger } from '@libp2p/logger';
3: import { multiaddr } from '@multiformats/multiaddr';
[vite-plugin-sveltekit-compile] "setMaxListeners" is not exported by "__vite-browser-external", imported by "node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/connection-manager/utils.js".
file: /home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/connection-manager/utils.js:1:9
1: import { setMaxListeners } from 'events';
            ^
2: import { logger } from '@libp2p/logger';
3: import { multiaddr } from '@multiformats/multiaddr';
✓ built in 9.53s
error during build:
RollupError: "setMaxListeners" is not exported by "__vite-browser-external", imported by "node_modules/.pnpm/libp2p@0.45.9/node_modules/libp2p/dist/src/connection-manager/utils.js".
    at error (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:2245:30)
    at Module.error (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:13604:16)
    at Module.traceVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:14029:29)
    at ModuleScope.findVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:12547:39)
    at FunctionScope.findVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at ChildScope.findVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at BlockScope.findVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at BlockScope.findVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at TrackingScope.findVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
    at BlockScope.findVariable (file:///home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/rollup@3.27.2/node_modules/rollup/dist/es/shared/node-entry.js:7082:38)
 ELIFECYCLE  Command failed with exit code 1.
weboko commented 1 year ago

@agazso, is it the same for @waku/sdk of 0.0.19?

agazso commented 1 year ago

@agazso, is it the same for @waku/sdk of 0.0.19?

Yes, it is the same with version 0.0.19

agazso commented 1 year ago

I tried out and the first version which starts breaking is 0.0.17 of @waku/sdk. I see in that version there was a libp2p version upgrade which may explain this.

https://github.com/waku-org/js-waku/releases/tag/sdk-v0.0.17

weboko commented 11 months ago

Origination of the problem is the approach to how vite works. It's stance is that they do not include anything but browser-related dependencies and if anyone needs they should add polyfills themself.

Tried different ways to handle that on js-waku level of abstraction but couldn't find any.

So as per advice from Vite - making an issue on the side of libp2p to address it.

As mitigation following steps can be done:

Issue on libp2p side https://github.com/libp2p/js-libp2p/issues/2110