Support for the experimental syntax 'classProperties' isn't currently enabled

项目中使用高级语法报错,

报错信息

SyntaxError: E:\workdata\webpackVue\src\index.js: Support for the experimental syntax 'classProperties' isn't currently enabled (22:8):

20 |
21 | class Dog {
> 22 | name = 'bigWhite'
| ^
23 | static color = 'yellow'
24 | }
25 | const d = new Dog()

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.

这是因为在js中写了高级语法,浏览器不支持,需要安装babel插件,并配置,这里报错信息会提示我们安装插件

在项目中安装 npm i @babel/plugin-proposal-class-properties -D

在.babelrc文件中配置

 

"presets": [
    "@babel/preset-env"
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties"
  ]

 

 

 

配置后就能正常运行,并且也会转化为普通语法

 

posted @ 2019-06-02 19:23  潇湘羽西  阅读(1538)  评论(0编辑  收藏  举报