今天接受了一个 Vue 项目,在执行 npm run serve
命令运行项目时报错:
Error: No ESLint configuration found.
安装 ESlint 并初始化配置:
全局安装 ESLint :
npm i eslint -g
生成配置文件:
eslint --init
根据自己的项目需求进行设置:
√ How would you like to use ESLint? · problems
√ What type of modules does your project use? · esm
√ Which framework does your project use? · vue
√ Does your project use TypeScript? · No / Yes
√ Where does your code run? · browser
√ What format do you want your config file to be in? · JavaScript
The config that you've selected requires the following dependencies:
eslint-plugin-vue@latest
? Would you like to install them now with npm? » Yes
在项目中安装 ESLint :
npm install eslint --save-dev
生成配置文件:
./node_modules/.bin/eslint --init
初始化成功后,会在项目根目录生成一个 .eslintrc.js
文件,文件内容:
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:vue/essential"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"vue"
],
"rules": {
}
};
这里我还遇到一个问题,运行时报错:
Syntax Error: Error: D:\vue\rcyj-settle-web\.eslintrc.js:
Environment key "es2021" is unknown
at Array.forEach (<anonymous>)
这是因为 eslint-plugin-standard
版本不兼容。
将 eslint-config-standard
版本进行降级为 ^14.1.1
:
npm i eslint-config-standard@14.1.1 eslint-plugin-standard -D --save
然后删除 .eslintrc.js
里面 "env"
中的 "es2021"
属性即可。
未经允许不得转载:w3h5-Web前端开发资源网 » npm运行项目报错:No ESLint configuration found 的解决方法
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有