错误提示:Parsing error: The keyword ‘import‘ is reserved
2025年,使用vue-cli工具新建Vue2项目时,会同时自动安装ESlint,有时VScode的项目文件的某行代码下会出现红色波浪线,悬停时会弹出如下提示:
Parsing error: The keyword ‘import‘ is reserved
启动项目时也会报错,如下:
- 解决方法
在项目的根目录下的文件.eslintrc.js(如果没有自己新建一个),放入以下代码:
js
module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
},
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
'rules': {
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
},
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
'rules': {
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}错误提示:
sh
ERROR Failed to compile with 1 error 15:00:25
[eslint] Failed to load plugin 'html' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-html'
Require stack:
- 【你的项目目录(请忽略)】\__placeholder__.js
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR in [eslint] Failed to load plugin 'html' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-html'
Require stack:
- 【你的项目目录(请忽略)】\__placeholder__.js
webpack compiled with 1 errorERROR Failed to compile with 1 error 15:00:25
[eslint] Failed to load plugin 'html' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-html'
Require stack:
- 【你的项目目录(请忽略)】\__placeholder__.js
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR in [eslint] Failed to load plugin 'html' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-html'
Require stack:
- 【你的项目目录(请忽略)】\__placeholder__.js
webpack compiled with 1 error- 解决方案
通常这是使用vue-cli新建vue2项目时,自带的ESlint配置导致的出错,找到package.json文件,删除"@vue/cli-plugin-eslint": "~5.0.0",这一行,重新运行yarn serve即可。
liang14658fox