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

TypeError: class constructors must be invoked with |new| #10168

Open
kottackalsulvin opened this issue Jul 5, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@kottackalsulvin
Copy link

commented Jul 5, 2019

Hi,
I have the below shown error while integrating a libp2p application in Ethereum Blockchain application. The error message is:

TypeError: class constructors must be invoked with |new|

My code is like below:

const node = new Node({peerInfo})

node.start((err) => {
console.log("node start");
if (err) callback(err)
callback(null, node)
})
.....
class Node extends libp2p {
constructor (peerInfo,opts) {
const wstar = new WebRTCStar()
const DEFAULT_OPTS = {
modules:{
transport: [new WS(), wstar], 
connEncryption: [secio],
streamMuxer: [mplex],
peerDiscovery: [ wstar.discovery ]
}
}
super(defaultsDeep(opts,peerInfo, DEFAULT_OPTS))
}
}
...

My webpack.config.js code is as below:

module: {
rules: [
{ test: /\.json$/, use: 'json-loader' },
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]},
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: {
test: /(node_modules|bower_components)/,
not: [
/libp2p/
]
},
query: {
presets:['es2015'],
plugins:['transform-object-rest-spread']
}
}
]
},

Environment
Npm / Node version: 6.9.0 / 10.16.0
webpack: 3.11.0
babel-loader:7.1.0
Os:Ubuntu 18.04

I don’t understand why showing the error messages. I tested the same libp2p application in meanstack and it works fine. Any ideas?

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Jul 5, 2019

Hey @kottackalsulvin! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

The problem is that native classes (i.e. libp2p) can't be extended by transpiled classes (Node).
You have two options:

Does your environment support classes?
yes -> don't transpile them in your code
no -> you also have to transpile them inside the libp2p library, otherwise it won't work.

@kottackalsulvin

This comment has been minimized.

Copy link
Author

commented Jul 6, 2019

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

commented Jul 6, 2019

Linking at your config they should already be transpiles, but there must be a problem somewhere.
Can you check in your webpack output if there really are untranspiled classes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.