VS Code ESLint — resolve plugins from custom directory

Viewed 624

How can I get ESLint setup with VS Code when my node_modules is not in the workspace root?

root/
  third_party/
     node_modules/
  .eslintrc
  src/
    (source files)

In the VS Code settings, I have ESLint setup to load from the custom node_modules location:

"eslint.nodePath": "third_party/node_modules"

However, I'm still getting the following error message:

Failed to load plugin '@typescript-eslint' declared in '.eslintrc': Cannot find module '@typescript-eslint/eslint-plugin'
Require stack:
- /path/to/repo/__placeholder__.js
Referenced from: /path/to/repo/.eslintrc
Happened while validating /path/to/repo/src/index.ts
This can happen for a couple of reasons:
1. The plugin name is spelled incorrectly in an ESLint configuration file (e.g. .eslintrc).
2. If ESLint is installed globally, then make sure '@typescript-eslint/eslint-plugin' is installed globally as well.
3. If ESLint is installed locally, then '@typescript-eslint/eslint-plugin' isn't installed correctly.

And here's my .eslintrc:

{
    "plugins": [],
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": "latest",
        "project": "./tsconfig.json"
    },
    "ignorePatterns": ["node_modules"]
}

I saw there's a CLI option (--resolve-plugins-relative-to) that will tell ESLint where to look for the plugins, but that doesn't seem to be exposed to the .eslintrc or in the VS Code extension settings.

https://eslint.org/docs/user-guide/command-line-interface#--resolve-plugins-relative-to

Due to my specific circumstance, changing the directory structure is not possible.

0 Answers
Related