npm运行构建上的Babel-Loader语法错误 [英] Babel-Loader Syntax error on npm run build
问题描述
我对webpack的能力不是很强,并且正在尝试将webpack从V3更新到V4,并设法将我的webpack配置更新到不会向我抛出折旧错误的程度,但是现在我陷入了来自babel-loader:
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:
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 ...
在我的webpack配置中,我有这个:
In my webpack config I have this:
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",
我尝试使用不同版本的babel进行了多次尝试,但总是以此消息结尾.有人可以看到我犯的任何明显错误吗?
I have tried multiple times with diffent versions of babel but always end up at this message. Can anyone see any obvious mistakes I am making?
推荐答案
SyntaxError: Unexpected token ...
表示您的节点没有在编译ES6.您是否已将node/npm升级到相对较新的版本?
The SyntaxError: Unexpected token ...
implies that your node isn't transpiling ES6. Have you upgraded node/npm to relatively new versions?
此外,如果要更改版本,我建议在再次运行npm install
之前先删除node_modules
文件夹和package-lock.json
文件.
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运行构建上的Babel-Loader语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!