简体   繁体   English

npm 运行构建上的 Babel-Loader 语法错误

[英]Babel-Loader Syntax error on npm run build

I am not very strong with webpack and am trying to update webpack from V3 to V4 and have managed to update my webpack config to the point where its not throwing depreciation errors at me, but I am now stuck on a syntax error from babel-loader:我对 webpack 不是很强大,我正在尝试将 webpack 从 V3 更新到 V4,并设法将我的 webpack 配置更新到了从 babel-loader 出现的语法错误,但我现在没有在 babel-loader 上抛出语法错误:

      Module build failed (from ./node_modules/babel-loader/lib/index.js):
      /path/react/node_modules/schema-utils/dist/util/hints.js:16
      const currentSchema = { ...schema
      SyntaxError: Unexpected token ...

In my webpack config I have this:在我的 webpack 配置中,我有这个:

         test: /\.(js|jsx)$/,
            use: [
              {
                loader: 'babel-loader',
                options: {
                  presets: [
                    '@babel/preset-env',
                    '@babel/preset-react',
                    {
                      plugins: [
                        '@babel/plugin-proposal-class-properties'
                      ]
                    }
                  ],
                  compact: true,
                  cacheDirectory: false, // @todo: legacy option: true
                },
              }
            ]

and I am using the following versions:我正在使用以下版本:

 "@babel/core": "^7.1.6",
 "@babel/plugin-proposal-class-properties": "^7.8.3",
 "@babel/preset-env": "^7.1.6",
 "@babel/preset-react": "^7.0.0",
 "babel-loader": "^8.0.4",

I have tried multiple times with diffent versions of babel but always end up at this message.我曾多次尝试使用不同版本的 babel,但总是以这条消息结束。 Can anyone see any obvious mistakes I am making?谁能看到我犯的任何明显错误?

The SyntaxError: Unexpected token... implies that your node isn't transpiling ES6. SyntaxError: Unexpected token...意味着您的节点没有转译 ES6。 Have you upgraded node/npm to relatively new versions?您是否将 node/npm 升级到相对较新的版本?

Also, if you're changing versions, I would suggest deleting your node_modules folder and package-lock.json file before running npm install again.另外,如果您要更改版本,我建议您在再次运行npm install之前删除您的node_modules文件夹和package-lock.json文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 webpack:babel-loader的语法错误 - webpack: syntax error with babel-loader babel-loader语法错误仅适用于导入的模块 - babel-loader syntax error only for imported modules babel-loader 破坏了 npm 包中的 `this` 变量 - babel-loader breaks the `this` variable in an npm package 使npm软件包与babel(Babel-loader)一起使用 - Getting npm packages to work with babel (babel-loader) babel-loader 和版本的问题,node_modules (npm) 中也不存在 babel-loader 文件夹 - Problem with babel-loader and version, also babel-loader folder not present in node_modules (npm) 错误:无法解析模块“babel-loader” - Error: Cannot resolve module 'babel-loader' babel-loader不转码且无错误 - babel-loader not transpiling and without error babel-loader错误 - TypeError:val不是函数 - babel-loader error - TypeError: val is not a function 为什么我会收到此错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js):语法错误意外令牌,预期“,” - Why am I getting this error: Module build failed (from ./node_modules/babel-loader/lib/index.js): Syntax Error Unexpected token, expected "," 错误:模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):语法错误: - Error: Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM