简体   繁体   English

使用Webpack4和Babel的React应用程序模块构建失败

[英]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.

相关问题 模块构建失败 - Webpack、React、Babel - Module Build Failed - Webpack, React, Babel Webpack,React JSX,Babel:模块构建失败,“意外令牌”为空? - Webpack, React JSX, Babel: Module build failed, “unexpected token” empty? babel 意外令牌反应模块构建失败 - babel unexpected token react module build failed Webpack / Babel 错误:模块构建失败:(SystemJS)ENOENT:没有这样的文件或目录 - Webpack / Babel Error: Module build failed: (SystemJS) ENOENT: no such file or directory 无法使用webpack 4和babel 7在我的react-application中导入jsx模块 - Unable to import a jsx module in my react-application with webpack 4 and babel 7 Webpack模块构建失败的意外令牌(rails反应构建) - Webpack module build failed unexpected token (rails react build) Webpack babel-loader 运行时:模块构建失败:TypeError:this.setDynamic 不是函数 - Webpack babel-loader runtime: Module build failed: TypeError: this.setDynamic is not a function 使用React和Webpack时如何解决“模块构建失败:SyntaxError:意外令牌”错误? - How to fix “Module build failed: SyntaxError: Unexpected token” error when using React and Webpack? 导入React组件时Webpack模块构建失败 - Webpack Module build failed when importing React components Webpack@4.41 在构建 React 脚本时出现 babel-loader@8 错误(模块解析失败:意外令牌) - Webpack@4.41 with babel-loader@8 error while building react scripts (Module parse failed: Unexpected token)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM