Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught (in promise) TypeError: Class constructor Gossipsub cannot be invoked without 'new' #323

Closed
TheBojda opened this issue Oct 24, 2021 · 12 comments · Fixed by #328
Closed
Projects

Comments

@TheBojda
Copy link

Problem

I've installed waku through npm (npm install js-waku), and the below minimal js throws the "Uncaught (in promise) TypeError: Class constructor Gossipsub cannot be invoked without 'new'" error.

This is my JS file:
import 'regenerator-runtime/runtime'
import { Waku } from "js-waku";

async function init() {
await Waku.create({ bootstrap: true });
}

init();

@D4nte D4nte added this to New in js-waku Oct 24, 2021
@TheBojda
Copy link
Author

It works fine with release 0.13.1, so something went wrong from 0.14.0.

@D4nte
Copy link
Contributor

D4nte commented Oct 24, 2021

@TheBojda Thanks for the report! Can you try 0.14.1 please?

@TheBojda
Copy link
Author

Yes. It throws the error with 0.14.1.

@D4nte
Copy link
Contributor

D4nte commented Oct 26, 2021

ok thanks, will investigate.

@D4nte D4nte moved this from New to In Progress in js-waku Oct 26, 2021
@D4nte
Copy link
Contributor

D4nte commented Oct 26, 2021

I am not able to reproduce the issue.

You do mention that you are using a JS file but you are getting a TypeError.

Are you using TypeScript? If so, can you share your ts.config please?

Reproduction:

▶ cat index.mjs

import 'regenerator-runtime/runtime.js'
import { Waku } from "js-waku";

async function init() {
await Waku.create({ bootstrap: true });
}

init();
▶ DEBUG=libp2p* node index.mjs
  libp2p:connection-manager options: {"maxConnections":null,"minConnections":25,"maxData":null,"maxSentData":null,"maxReceivedData":null,"maxEventLoopDelay":null,"pollInterval":2000,"autoDialInterval":10000,"movingAverageInterval":60000,"defaultPeerValue":1,"autoDial":true} +0ms
  libp2p:transports adding WebSockets +0ms
  libp2p:transports adding Circuit +1ms
  libp2p:peer-store:proto-book added provided protocols for QmP3Jz1TvQ1DpRKCqcSyMXf9XhQXdjWsGfbiZEKUXjywry +0ms
  libp2p:peer-store:proto-book added provided protocols for QmP3Jz1TvQ1DpRKCqcSyMXf9XhQXdjWsGfbiZEKUXjywry +1ms
  libp2p:peer-store:proto-book added provided protocols for QmP3Jz1TvQ1DpRKCqcSyMXf9XhQXdjWsGfbiZEKUXjywry +9ms
  libp2p libp2p is starting +0ms
  libp2p:transports no addresses were provided for listening, this node is dial only +12ms
  libp2p:gossipsub starting +0ms
  libp2p:peer-store:proto-book added provided protocols for QmP3Jz1TvQ1DpRKCqcSyMXf9XhQXdjWsGfbiZEKUXjywry +4ms
  libp2p:gossipsub started +2ms
  libp2p:gossipsub:score started +0ms
  libp2p:connection-manager started +27ms
  libp2p:bootstrap Starting bootstrap node discovery +0ms
  libp2p:peer-store:address-book added provided multiaddrs for 16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA +0ms
  libp2p connecting to discovered peer 16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA +27ms
  libp2p:dialer 1 tokens request, returning 1, 99 remaining +0ms
  libp2p libp2p has started +9ms
  libp2p:websockets dialing /dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA +0ms
  libp2p:websockets dialing node-01.gc-us-central1-a.wakuv2.prod.statusim.net:443 +19ms
  libp2p:websockets connected /dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA +864ms
  libp2p:websockets new outbound connection /dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA +4ms
  libp2p:upgrader Starting the outbound connection upgrade +0ms
  libp2p:upgrader selecting outbound crypto protocol [ '/noise' ] +1ms
  libp2p:upgrader encrypting outbound connection to {"id":"16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA","pubKey":"CAISIQP99JB4EKn12UYqGuCf7uWrIF0yeYsP/MN5RCAh+Exbvw=="} +216ms
  libp2p:noise Stage 0 - Initiator starting to send first message. +0ms
  libp2p:noise Stage 0 - Initiator finished sending first message. +7ms
  libp2p:noise Stage 1 - Initiator waiting to receive first message from responder... +1ms
  libp2p:noise Stage 1 - Initiator received the message. +248ms
  libp2p:noise Initiator going to check remote's signature... +2ms
  libp2p:noise All good with the signature! +5ms
  libp2p:noise Stage 2 - Initiator sending third handshake message. +1ms
  libp2p:noise Stage 2 - Initiator sent message with signed payload. +22ms
  libp2p:upgrader outbound selecting muxer [ '/mplex/6.7.0' ] +335ms
...

▶ cat package.json

{
  "name": "323-class-constructor-gossip",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "js-waku": "^0.14.1",
    "regenerator-runtime": "^0.13.9"
  }
}

@D4nte D4nte closed this as completed Oct 26, 2021
js-waku automation moved this from In Progress to Done Oct 26, 2021
@D4nte D4nte reopened this Oct 26, 2021
js-waku automation moved this from Done to Backlog Oct 26, 2021
@D4nte D4nte moved this from Backlog to Pending Author in js-waku Oct 26, 2021
@TheBojda
Copy link
Author

TheBojda commented Oct 26, 2021

Hi! I've used parcel.

This is my packages.json:

{
  "name": "waku-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "parcel build index.html",
    "start": "parcel index.html",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel-bundler": "^1.12.5"
  },
  "dependencies": {
    "js-waku": "^0.14.1"
  }
}

index.html:

<!doctype html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>Parcel sample</title>
</head>
<body>
 <script src="index.js"></script>
</body>
</html>

index.js:

import 'regenerator-runtime/runtime'
import { Waku } from "js-waku";

async function init() {
	await Waku.create({ bootstrap: true });
	}
	
init();

When you start it with npm start or parcel index.html. It throws the error in the browser.

I forgot to mention that I'm using it from a browser. :)

@D4nte D4nte moved this from Pending Author to Backlog in js-waku Oct 27, 2021
@D4nte
Copy link
Contributor

D4nte commented Oct 27, 2021

Thanks, I haven't tried parcel so I'll have to investigate.
FYI, I am going on leave for a month so apologies in advance as I am unlikely to investigate til then.

It should work in the browser as we have several examples that uses React TS and React JS or even Vanilla JS: https://github.com/status-im/js-waku/tree/main/examples

I am guessing the issue is with parcel default config.

@TheBojda
Copy link
Author

I've downloaded min-js-web-chat and changed the js-waku dependency:

"js-waku": "../../build/main" ->  "js-waku": "^0.14.1"

It throws the same error. So, something is wrong with the package in the npm registry, not a Parcel related problem. You should publish it a different way or something. :)

Until it, I can use 0.13.1.

@D4nte
Copy link
Contributor

D4nte commented Nov 26, 2021

Thank you for the investigation. Will review.

@D4nte D4nte moved this from Backlog to In Progress in js-waku Nov 26, 2021
js-waku automation moved this from In Progress to Done Nov 26, 2021
@D4nte
Copy link
Contributor

D4nte commented Nov 26, 2021

@TheBojda can you let me know if 0.14.2-rc.0 fixes the issue? thanks!

@TheBojda
Copy link
Author

Yay. Works like a charm. Ty :)

D4nte added a commit that referenced this issue Nov 30, 2021
### Changed

- Examples: JS examples uses local ESM folder to replicate behaviour of
js-waku publish package.

### Fixed

- `TypeError` issue related to constructors using js-waku in a JS
project
  ([#323](#323)).
@D4nte D4nte mentioned this issue Nov 30, 2021
@D4nte
Copy link
Contributor

D4nte commented Nov 30, 2021

Excellent, now released with 0.14.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants