You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: Class constructor Person cannot be invoked without 'new' / _possibleConstructorReturn (T7328) #4269
$ node ./extend-native-class-via-babel.js
/Users/balupton/Projects/edition-stuff/babel-class-issue/extend-native-class-via-babel.js:17
return _possibleConstructorReturn(this, Object.getPrototypeOf(Employee).apply(this, arguments));
^
TypeError: Class constructor Person cannot be invoked without 'new'
at new Employee (/Users/balupton/Projects/edition-stuff/babel-class-issue/extend-native-class-via-babel.js:17:77)
at Object.<anonymous> (/Users/balupton/Projects/edition-stuff/babel-class-issue/extend-native-class-via-babel.js:23:16)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:159:18)
at node.js:444:3
Babel fails to create code that is able to extend native classes
Unfortunately that is much easier said than done. ES6 classes cannot be extended with ES5-style code. If your platform supports native classes, your best bet is to use a preset that is targeted to your platform, like babel-preset-es2015-node5, so then Babel will not transform the ES6 classes in your own code and they will work properly.
Comment originally made by Benjamin Lupton (balupton)
If your platform supports native classes, your best bet is to use a preset that is targeted to your platform, like babel-preset-es2015-node5, so then Babel will not transform the ES6 classes in your own code and they will work properly.
I just hit this issue while trying to simplify babel-plugin-lodash trying to extend a class with Map.
Lodash avoids this issue by [[ https://github.com/lodash/lodash/blob/4.13.1-npm/_createCtorWrapper.js | using a switch statement ]] .
Activity
babel-bot commentedon May 1, 2016
Unfortunately that is much easier said than done. ES6 classes cannot be extended with ES5-style code. If your platform supports native classes, your best bet is to use a preset that is targeted to your platform, like
babel-preset-es2015-node5, so then Babel will not transform the ES6 classes in your own code and they will work properly.babel-bot commentedon May 1, 2016
Probably related to https://github.com/balupton/javascript-coffeescript-class-interop
In which case, I'm not sure what the solution is.
babel-bot commentedon May 1, 2016
Good suggestion, I'll give that a go!
babel-bot commentedon May 1, 2016
Okay, for my case, luckily the package I was consuming - https://github.com/bevry/fellow - uses https://github.com/bevry/editions - so I was able to change
require('fellow')torequire('fellow/es2015')which worked great.Happy to mark this as resolved, as my issue is now resolved, and doesn't seem possible for Babel to do anything here.
babel-bot commentedon Jul 16, 2016
I just hit this issue while trying to simplify
babel-plugin-lodashtrying to extend a class withMap.Lodash avoids this issue by [[ https://github.com/lodash/lodash/blob/4.13.1-npm/_createCtorWrapper.js | using a switch statement ]] .
babel-bot commentedon Jul 16, 2016
I've opened a PR – #3582
Fix extending es classes in modules (see babel/babel#4269)
Fix extending es classes in modules (see babel/babel#4269)