[英]Module Build Failed for react application using Webpack4 and Babel
My application is not transpiling the JSX from my react application. 我的应用程序没有从我的React应用程序中转译JSX。
Here is my webpack config for babel: 这是我针对babel的webpack配置:
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
Here is the configuration for .babelrc: 这是.babelrc的配置:
{
"plugins": [
"@babel/plugin-transform-react-jsx-self",
"transform-class-properties"
]
} }
Here are the dev dependencies i installed: 这是我安装的开发依赖项:
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-stage-2": "^7.0.0",
"babel-loader": "^8.0.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-react-jsx": "^6.24.1",
as you can see ive played around with a few different dependencies but im pretty sure the issue lies in me not understanding how to properly configure it in my babelrc (this is my first attempt at this) 正如您所看到的,我在玩一些不同的依赖项,但是我很确定问题出在我不了解如何在babelrc中正确配置它(这是我的第一次尝试)
Other answers ive read to solve this use babel presets in the webpack config and babelrc, but babel has recently deprecated this in Babel7 我已阅读其他解决方案来解决此问题,以在webpack配置和babelrc中使用babel预设,但是babel最近在Babel7中弃用了此选项
So in case anyone has the same issue. 因此,万一有人有同样的问题。 This configuration of the babelrc is now working for me:
babelrc的此配置现在对我有用:
{
"presets": [
["@babel/env"],
["@babel/preset-react"]
],
"plugins": [
["transform-class-properties"],
["@babel/plugin-transform-react-jsx-self"]
]
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.