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

报错信息

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"
  ]

 

 

 

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

 

相关文章:

  • 2022-02-10
  • 2022-02-28
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-07-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2022-01-26
  • 2022-12-23
相关资源
相似解决方案