我正在跟随一个教程,当我尝试建立反应时,我得到一个错误。
Duplicate symbol 'ControlEvent:VerifyReadyDlg/Back/NewDialog/WelcomeDlg/Installed AND PATCH' found. This typically means that an Id is duplicated. Check to make sure all your identifiers of a given type (File, Component, Feature) are unique
我发现了类似的问题,因此我尝试根据此问题进行修复,但无济于事。 这是我的webpack.config.js:
Module build failed (from ./node_modules/babel-loader/lib/index.js)
5 | ReactDOM.render(
> 6 | <App />,
| ^
7 | document.getElementById('root')
8 | );
下面有package.json,module.exports = {
entry: './index.js',
output:{
path: __dirname,
filename: 'bundle.js'
},
module:{
rules:[
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: '/node_modules/'
}
]
}
}
是我在以前的解决方案中找到的。
"devDependencies"
这些是我最初的{
"name": "rtsupport",
"version": "1.0.0",
"description": "Realtime support frontend",
"main": "./index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"develop": "webpack --mode development --watch",
"build": "webpack --mode development"
},
"author": "",
"license": "ISC",
"dependencies": {
"node": "^10.15.2",
"react-dom": "^16.8.4"
},
"devDependencies": {
"@babel/core": "^7.0.0-bridge.0",
"babel": "^5.8.23",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"react": "^16.8.4",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
}
}
"devDependencies"
我的节点版本为:v11.10.1
尝试以下建议后:
"devDependencies": {
"@babel/core": "^7.3.4",
"babel": "^5.8.23",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.5"
}
我仍然遇到相同的错误。
答案 0 :(得分:1)
这个问题可以通过设置每个babel依赖来解决
<块引用>>=7.8.7
"devDependencies": {
"@babel/cli": "^7.13.10",
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/preset-react": "^7.12.13",
}
答案 1 :(得分:0)
好吧,如果您打算在其中使用JSX,我认为您的webpack测试需要包含.js文件:
test: /\.(js|jsx)$/
答案 2 :(得分:0)
使用该配置,您只告诉“翻译” .jsx文件,并且由于您的主文件是index.js,他没有加载该文件,请尝试添加此配置:
以此添加要由加载程序解析的js和jsx文件
rules: [
{
exclude: /node_modules/,
test: /\.js|.jsx?$/,
use: [
{ loader: 'babel-loader' }
]
}
]
我的错,我以为您有一个babelrc,我忘了您可以使用“ .babelrc”名称在与wepback.config相同的文件夹级别上创建文件,在这里您可以指定加载配置,并告诉babel加载“ react “插件
{
"presets": [
"stage-0",
"react",
"es2015"
],
"plugins": [
"transform-class-properties",
"transform-decorators-legacy",
"transform-object-rest-spread",
"transform-es2015-destructuring"
],
"env": {
"debug": true
}
}
答案 3 :(得分:0)
经过一整天的黑客攻击和浏览,我找到了解决方案。
module:{
rules:[
{
test: /\.jsx?$/,
exclude: '/node_modules/',
loader: 'babel-loader',
query:
{
presets:['react']
}
}
]
}
和package.json部分:
"devDependencies": {
"@babel/core": "^7.3.4",
"babel": "^5.8.23",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "^7.0.2",
"react": "^16.8.4",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
}