[英]Install ESLint + babel-eslint parser globally on Windows 10
I unsuccessfully tried to install ESLint globally running with babel-eslint as parser.我尝试安装以 babel-eslint 作为解析器全局运行的 ESLint,但没有成功。 I installed both packages globally on a Windows 10 machine:
我在 Windows 10 机器上全局安装了这两个软件包:
npm list --depth=0 -g
C:\Users\UserName\AppData\Roaming\npm
+-- @angular/cli@8.3.9
+-- babel-eslint@10.1.0
+-- create-react-app@3.4.1
+-- eslint@7.10.0
+-- nodemon@2.0.5
+-- npm@6.14.7
+-- npm-check-updates@3.1.23
+-- npm-install-peers@1.2.1
`-- typescript@3.6.4
A default .eslintrc
config file exists in my home directory: C:\\Users\\UserName
我的主目录中存在默认的
.eslintrc
配置文件: C:\\Users\\UserName
This works fine untill i specify babel-eslint
as parser
:这工作正常,直到我将
babel-eslint
指定为parser
:
{
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"parser": "babel-eslint",
"rules": {
"no-var": "error",
"no-use-before-define": "off",
"no-unused-vars": "warn",
"prefer-const": "warn",
"no-console": "off",
"func-names": "off",
"node/no-unsupported-features/es-syntax": "off"
}
}
ESLint server throws: ESLint 服务器抛出:
[Info - 11:06:04] Failed to load parser 'babel-eslint' declared in 'PersonalConfig': Cannot find module 'babel-eslint' Require stack: - C:\\Users\\UserName\\.eslintrc
[信息 - 11:06:04] 无法加载在“PersonalConfig”中声明的解析器“babel-eslint”:找不到模块“babel-eslint”需要堆栈:-C:\\Users\\UserName\\.eslintrc
Same happens by the way, as soon as I try to extend my config with air-bnb config, which is also globally installed.顺便说一下,只要我尝试使用 air-bnb 配置扩展我的配置,它也会发生同样的情况,该配置也是全局安装的。 How can I tell ESLint where to look for dependencies since they are not installed in
C:\\Users\\UserName
but in C:\\Users\\UserName\\AppData\\Roaming\\npm
?我如何告诉 ESLint 在哪里查找依赖项,因为它们没有安装在
C:\\Users\\UserName
而是安装在C:\\Users\\UserName\\AppData\\Roaming\\npm
?
Try this:尝试这个:
"parser": "C:/Users/<username>/AppData/Roaming/npm/node_modules/babel-eslint",
Not a perfect solution but it works.不是一个完美的解决方案,但它有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.