Babel error: Class constructor Foo cannot be invoked without 'new'

前端 未结 2 608
既然无缘
既然无缘 2020-12-19 00:23

I am using babel to transpile.

I have class BaseComponent which is extended by class Logger.

When I run new Logger() i

2条回答
  •  Happy的楠姐
    2020-12-19 00:57

    Due to the way ES6 classes work, you cannot extend a native class with a transpiled class. If your platform supports native classes, my recommendation would be, instead of using the preset es2015, use es2015-node5, assuming you're on Node 5. That will cause Babel to skip compiling of classes so that your code uses native classes, and native classes can extend other native classes.

提交回复
热议问题