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

Typerror when calling super() in constructor #2

Open
latenssi opened this issue Feb 28, 2020 · 2 comments
Open

Typerror when calling super() in constructor #2

latenssi opened this issue Feb 28, 2020 · 2 comments

Comments

@latenssi
Copy link

latenssi commented Feb 28, 2020

I was debugging an error in js-libp2p which caused it to be unable to connect to peers in a production build in browser build by webpack using create-react-app framework.

I finally found this error message in the logs when a connection fails:
TypeError: Failed to construct 'AbortController': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

The problem is the super() call in the constructor of TimeoutController here: master/index.js#L10.
If I replace the implementation of TimeoutController with one that uses JS prototypes rather than JS classes I get no errors and the connections happen as intended. Not sure if it actually works anymore like that tho'.

I do not know why this happens only in a production build and not in a development setup (webpack-dev-server) but this does happen consistently and prevents libp2p connections in create-react-app based apps.

@jacobheun
Copy link
Owner

@latenssi what is your es build target for webpack? I am wondering if the production build is compiling to es5 resulting in a _super.call(this) type of call, which might cause this error. The dev server is likely just using es6 targets.

@latenssi
Copy link
Author

latenssi commented Feb 28, 2020

Yes you are correct, my create-react-app setup seems to be using ES 5 as target.

Perhaps the easiest way to fix my problem is considering ES 6 as target.

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

No branches or pull requests

2 participants