static class property not working with Babel

前提是你 提交于 2019-12-04 10:50:23

Class properties aren't part of the ES2015 spec, so they're not part of the ES2015 Babel preset either. The proposal to add class properties to the language is currently at Stage 2 of the standardization process, so you need the Stage 2 preset.

https://babeljs.io/docs/plugins/preset-stage-2/

Alternatively, you could just install the class properties plugin on its own:

http://babeljs.io/docs/plugins/transform-class-properties/

ABHISHEK THEPRA

As stage-2 , stage-3 or any other stage preset are removed in babel 7 or newer so you have to add plugin separately. Please use "require()" for importing plugin otherwise it wont work. Here is the .bablerc file -

module.exports = {
  plugins: [
    [require("@babel/plugin-proposal-class-properties"), { loose: false }]
  ],
  presets: ["@babel/preset-env", "@babel/preset-react"]
}; 

@Joe thanks yes the plugin which you mentioned will help to solve the problem. In my case the way I solved it was by making sure to have all .babelrc dependency copied to jsdoc babel property as well I was missing this piece which was giving me all the errors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!