我正在 Front-end Masters 上学习 React 课程,我们需要修改 babel 配置以允许在类组件中使用状态初始化,如:state = {index: 0}
。但是,在运行以下命令后:npm install -D babel-eslint @babel/core @babel/preset-env @babel/plugin-proposal-class-properties @babel/preset-react
并在根目录下创建一个.babelrc
文件并将其修改为如下内容:
{ "presets": ["@babel/preset-react", "@babel/preset-env"], "plugins": ["@babel/plugin-proposal-class-properties"] }
.
我遇到了以下错误:
/home/rahat/Documents/react_adopt_me/src/App.js: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
Duplicates detected are:
[
{
"alias": "/home/rahat/Documents/react_adopt_me/src/node_modules/@babel/plugin-proposal-class-properties/lib/index.js",
"dirname": "/home/rahat/Documents/react_adopt_me/src",
"ownPass": false,
"file": {
"request": "@babel/plugin-proposal-class-properties",
"resolved": "/home/rahat/Documents/react_adopt_me/src/node_modules/@babel/plugin-proposal-class-properties/lib/index.js"
}
},
{
"alias": "base$2",
"options": {
"loose": "#__internal__@babel/preset-env__prefer-false-but-true-is-ok-if-it-prevents-an-error"
},
"dirname": "/home/rahat/Documents/react_adopt_me/src",
"ownPass": false
}
]