Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

CustomEvent is not a constructor error after upgrading to 0.15 #69

Closed
jesperjohansson opened this issue May 30, 2017 · 9 comments
Closed
Labels

Comments

@jesperjohansson
Copy link

This line gives an error:
child.dispatchEvent(new CustomEvent('e', {bubbles: true})); in trigger.js:169

Polyfill needed?

@webpro webpro added the bug label Jun 7, 2017
@webpro
Copy link
Owner

webpro commented Jun 9, 2017

In what browser or environment are you getting this error?

There is a polyfill, but only for environments having a window and window.document.

@alexandernanberg
Copy link

I'm seeing this error as well, in both Chrome 59 and Safari etc. We're using webpack to bundle our code.

// example.js
import $ from 'domtastic';

$('body').on('click', 'h1', (e) => {
  console.log(e);
});

throws this error
image

@webpro
Copy link
Owner

webpro commented Jul 4, 2017

Could it be that this is broken since DOMtastic v0.13? (change: 8710c24#diff-34a6d62af0cf0b784f8444529f3130ef).

Not sure what could cause this issue in the changes in the 0.15 release. I've changed the esnext:main property to module in package.json, which should maybe be esnext instead. Not sure how Webpack handles this these days. But even if it picks up the bundled/transpiled version it shouldn't be an issue, I guess.

@alexandernanberg
Copy link

Dont't think so, works with version ~0.14

It seems to be a problem with the module property, like you said, Webpack takes the entry from the module (which is not transpiled) property and not the main. The event error occurs because CustomEvent is an arrow function so you can't call as a constructor with new. Babel transpiles it into a regular function with a .bind() and then you can call it as a constructor.

Been reading a bit about how to handle this problem which seem to be pretty widespread but it doesn't look like anyone have solved it completely yet.

Similar issues here nfl/react-helmet#190, webpack/webpack#2902

@webpro
Copy link
Owner

webpro commented Jul 5, 2017

Thanks, @alexandernanberg. I'm starting to realize that module is only about the module syntax (ESM), but the source code of this lib has (much) more ES6 syntax indeed. @rauschma proposes to use the esnext property, but this doesn't seem to be supported by Webpack (yet).

I've just released v0.15.1 with module being removed (actually reverted back to esnext:main, in case some still rely on it).

@alexandernanberg
Copy link

@webpro Great, tested again and now it works. Thanks for the quick fix!

I think this issue can be closed now

@webpro
Copy link
Owner

webpro commented Jul 5, 2017

Thanks!

@magicspon
Copy link

Hello,

I'm getting this error in 0.15.3
image

any thoughts?

@webpro
Copy link
Owner

webpro commented Nov 18, 2017

I think I've fixed this in v0.15.4.

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

No branches or pull requests

4 participants