今天接受了一个 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: [email protected] ? 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 [email protected] eslint-plugin-standard -D --save
然后删除 .eslintrc.js
里面 "env"
中的 "es2021"
属性即可。
未经允许不得转载:w3h5 » npm运行项目报错:No ESLint configuration found 的解决方法
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/150527.html