Unexpected “Uncaught TypeError: XXX is not a constructor” errors with Babel and ES6

前端 未结 6 485
無奈伤痛
無奈伤痛 2020-12-29 19:04

I am giving a try to Webpack, and am giving a try to the instructions in this tutorial, give or take a few custom things.

This is simple code, really, but I\'m quite

6条回答
  •  抹茶落季
    2020-12-29 19:54

    I was able to fix this by adding babel-plugin-add-module-exports to the .babelrc file

    npm install babel-plugin-add-module-exports --save-dev

    {
      "presets": ["@babel/env"],
      "plugins": ["add-module-exports"]
    }
    

    this adds

    module.exports = exports.default;
    

    to the last line when compiling the class with babel.

提交回复
热议问题