今天接受了一个 Vue 项目,在执行 npm run serve
命令运行项目时报错:
Error: No ESLint configuration found.
解决方法:
安装 ESlint 并初始化配置:
方法一:
全局安装 ESLint :
代码语言:javascript复制npm i eslint -g
生成配置文件:
代码语言:javascript复制eslint --init
根据自己的项目需求进行设置:
代码语言:javascript复制√ 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]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x' a.substr(0,2)|0,n=2;a.length-n;n =2)e ='%' ('0' ('0x' a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
? Would you like to install them now with npm? » Yes
方法二:
在项目中安装 ESLint :
代码语言:javascript复制npm install eslint --save-dev
生成配置文件:
代码语言:javascript复制./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": {
}
};
这里我还遇到一个问题,运行时报错:
代码语言:javascript复制Syntax Error: Error: D:vuercyj-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]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x' a.substr(0,2)|0,n=2;a.length-n;n =2)e ='%' ('0' ('0x' a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */ eslint-plugin-standard -D --save
然后删除 .eslintrc.js
里面 "env"
中的 "es2021"
属性即可。
未经允许不得转载:w3h5 » npm运行项目报错:No ESLint configuration found 的解决方法