2

I unsuccessfully tried to install ESLint globally running with babel-eslint as parser. I installed both packages globally on a Windows 10 machine:

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

This works fine untill i specify babel-eslint as 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:

[Info - 11:06:04] Failed to load parser 'babel-eslint' declared in 'PersonalConfig': Cannot find module 'babel-eslint' Require stack: - 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. 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?

FelHa
  • 1,043
  • 11
  • 24
  • In general, you shouldn't install them globally, though. Is there a particular reason why you'd want to do that? – AKX Oct 16 '20 at 10:09
  • I wanted a default config for small projects so that I don't have to install eslint locally for such projects every time. – FelHa Oct 16 '20 at 10:12
  • 1
    The proper way to do that is to have your own `eslint-config-felha`, after which you can do `npm i eslint eslint-config-felha` and simply add `extends: eslint-config-felha` to your .eslintrc (or write a small tool, e.g. `eslint-config-felha-init` that does that). – AKX Oct 16 '20 at 10:13

1 Answers1

1

Try this:

 "parser": "C:/Users/<username>/AppData/Roaming/npm/node_modules/babel-eslint",

Not a perfect solution but it works.