小编Y. *_*hra的帖子

Babel 插件类属性——React 箭头函数

我正在使用 npm 运行一个 React 项目。经过数小时的研究和试验,到处都说我必须将以下代码添加到我的“.babelrc”文件中,我的目录中没有并且无法创建:

{
  "plugins": [
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行代码时,这会导致以下错误:

ERROR in ./src/components/NavBar/Menu.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/ymoondhra/Desktop/yt-web/src/components/NavBar/Menu.js:
Support for the experimental syntax 'classProperties' isn't currently enabled
 (20:10):
  18 |     }
  19 | 
> 20 |     fast = () => {
     |          ^
  21 |         this.speed = 100;
  22 |     }
  23 | 
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' 
section of your Babel config to enable transformation.
Run Code Online (Sandbox Code Playgroud)

plugins reactjs babeljs arrow-functions

4
推荐指数
1
解决办法
5423
查看次数

标签 统计

arrow-functions ×1

babeljs ×1

plugins ×1

reactjs ×1