Y. *_*hra 4 plugins reactjs babeljs arrow-functions
我正在使用 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)
3小时后找到了我的问题的解决方案:–在根目录中创建一个名为“babel.config.js”的文件。– 把这个放在文件里。– 重新运行程序(即 npm start)。
module.exports = {
presets: [ "@babel/preset-env", "@babel/preset-react" ],
plugins: [ "@babel/plugin-transform-arrow-functions", "@babel/plugin-proposal- class-properties" ]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5423 次 |
| 最近记录: |