Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code's instance of Eslint cannot resolve paths in monorepo

I have a project that has a following structure:

modules
│   ├── client
│       ├── .eslintrc.json
│   └── backend
│       ├── .eslintrc.json
...

The problem is, that when I open the project in the parent folder of modules (project's root folder), Eslint instance running inside of VS Code is unable to resolve any import path, aside from those pointing to node_modules. If I run Eslint inside client those paths are resolved without a problem.

I have found that if you have your Eslint config in javascript you are able to use __dirname and this I assume should combat this issue, but those features are not available to me in JSON. Is there any alternative to this inside JSON? Or will I have to remake those configs into javascript?

Thanks in advance.

like image 760
MalwareMoon Avatar asked Nov 05 '25 20:11

MalwareMoon


2 Answers

I solved this with the eslint.workingDirectories setting.

You can list all directories individually, but I used the pattern option like:

"eslint.workingDirectories": [
  { "pattern": "./packages/*/" }
]
like image 67
jrjohnson Avatar answered Nov 07 '25 11:11

jrjohnson


VS Code may have problems understanding in which folders ESLint needs to run.

This can be fixed by going to your VS Code Settings (CMD + , on Mac), switching to Workspace and finding eslint.workingDirectories and setting it to: [{ "mode": "auto" }].

This approach has some caveats and there are alternatives, see more here: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint#settings-options

like image 29
Kabece Avatar answered Nov 07 '25 11:11

Kabece



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!