在 运行 React 应用程序时发现重复的 __self 道具
Duplicate __self prop found when running react app
我在 React 应用程序中 运行 npm 运行 时收到此错误:
Syntax Error index.js: Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel
plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config
7 | ReactDOM.render(
8 | <React.StrictMode>
> 9 | <App />
| ^^^^^^^
10 | </React.StrictMode>,
11 | document.getElementById('root')
12 | );
我的项目中没有 babel 配置文件,也找不到 react 已经在使用的配置文件。我该如何解决?
package.json 依赖项(我之前有 运行 npm 运行 eject 但没有粘贴所有依赖项以缩短它):
"dependencies": {
"@babel/core": "^7.14.3",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.0",
"babel-loader": "8.1.0",
"babel-plugin-named-asset-import": "^0.3.7",
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "^10.0.0",
"bfj": "^7.0.2",
"html-webpack-plugin": "4.5.0",
"identity-obj-proxy": "3.0.0",
"jest": "26.6.0",
"jest-circus": "26.6.0",
"jest-resolve": "26.6.0",
"jest-watch-typeahead": "0.6.1",
"react": "^17.0.2",
"react-app-polyfill": "^2.0.0",
"react-dev-utils": "^11.0.3",
"react-dom": "^17.0.2",
"react-refresh": "^0.8.3",
"semver": "7.3.2",
"style-loader": "1.3.0",
"terser-webpack-plugin": "4.2.3",
"ts-pnp": "1.2.0",
"url-loader": "4.1.1",
"web-vitals": "^1.0.1",
"webpack": "4.44.2",
"webpack-dev-server": "3.11.1",
"webpack-manifest-plugin": "2.2.0",
"workbox-webpack-plugin": "5.1.4"
},
查看此答案React Native Jest SyntaxError: Duplicate __self prop found
另请参阅:https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
更新@babel/core和@babel/plugin-transform-react-jsx
npm update @babel/core @babel/plugin-transform-react-jsx
or
yarn upgrade @babel/core @babel/plugin-transform-react-jsx
然后添加一个文件.babelrc
// If you're using @babel/plugin-transform-react-jsx
{
"plugins": [
["@babel/plugin-transform-react-jsx", {
"runtime": "automatic"
}]
]
}
我在 React 应用程序中 运行 npm 运行 时收到此错误:
Syntax Error index.js: Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel
plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config
7 | ReactDOM.render(
8 | <React.StrictMode>
> 9 | <App />
| ^^^^^^^
10 | </React.StrictMode>,
11 | document.getElementById('root')
12 | );
我的项目中没有 babel 配置文件,也找不到 react 已经在使用的配置文件。我该如何解决?
package.json 依赖项(我之前有 运行 npm 运行 eject 但没有粘贴所有依赖项以缩短它):
"dependencies": {
"@babel/core": "^7.14.3",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.0",
"babel-loader": "8.1.0",
"babel-plugin-named-asset-import": "^0.3.7",
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "^10.0.0",
"bfj": "^7.0.2",
"html-webpack-plugin": "4.5.0",
"identity-obj-proxy": "3.0.0",
"jest": "26.6.0",
"jest-circus": "26.6.0",
"jest-resolve": "26.6.0",
"jest-watch-typeahead": "0.6.1",
"react": "^17.0.2",
"react-app-polyfill": "^2.0.0",
"react-dev-utils": "^11.0.3",
"react-dom": "^17.0.2",
"react-refresh": "^0.8.3",
"semver": "7.3.2",
"style-loader": "1.3.0",
"terser-webpack-plugin": "4.2.3",
"ts-pnp": "1.2.0",
"url-loader": "4.1.1",
"web-vitals": "^1.0.1",
"webpack": "4.44.2",
"webpack-dev-server": "3.11.1",
"webpack-manifest-plugin": "2.2.0",
"workbox-webpack-plugin": "5.1.4"
},
查看此答案React Native Jest SyntaxError: Duplicate __self prop found
另请参阅:https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
更新@babel/core和@babel/plugin-transform-react-jsx
npm update @babel/core @babel/plugin-transform-react-jsx
or
yarn upgrade @babel/core @babel/plugin-transform-react-jsx
然后添加一个文件.babelrc
// If you're using @babel/plugin-transform-react-jsx
{
"plugins": [
["@babel/plugin-transform-react-jsx", {
"runtime": "automatic"
}]
]
}