Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint.nodePath only works with absolute paths in multi module vscode workspaces #1225

Open
jousby opened this issue Mar 28, 2021 · 15 comments
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@jousby
Copy link

jousby commented Mar 28, 2021

I'm looking to manage a multi module / monorepo typescript project with Yarn 2 workspaces + VSCode Workspaces.
I have one eslintrc.yml file in the root folder of my project that configures eslint for all sub projects/packages. I have this working with one catch in that I have to make the the 'eslint.nodePath' property in my . code-workspace file an absolute path for the vscode-eslint extension to work. i.e

/.code-workspace

{
  "folders": [
    {
      "name": "✨ myproject",
      "path": "."
    },
    {
      "name": "⚙️ package1",
      "path": "packages/package1"
    },
    {
      "name": "⚙️ package2",
      "path": "packages/package2"
    }
  ],
  "settings": {
    "search.exclude": {
      "**/.yarn": true,
      "**/.pnp.*": true
    },
    // The offending absolution path
    "eslint.nodePath": "/Users/jim/code/scratch/myproject/.yarn/sdks",
    // The originally generated and preferable relative path
    // "eslint.nodePath": ".yarn/sdks",
    "typescript.tsdk": ".yarn/sdks/typescript/lib",
    "typescript.enablePromptUseWorkspaceTsdk": true,
    "editor.codeActionsOnSave": {
      "source.fixAll": true
    } 
  }
}

This means i can't check the *.code-workspace file in to my project to help others get started quickly with vscode.

When i use the original relative path and I navigate to a .ts file in one of the sub packages it complains that the eslint file can't be loaded. It feels like the eslint extension might be trying to find a '.yarn/sdk' folder relative to base of the current sub package instead of continuing to look at the base of the project perhaps?

@dbaeumer
Copy link
Member

Have you confirmed the nodePath setting. Please see the discussion here: #1201 for the details why that got introduced. It also contains an example of the nodePath being relative.

I will close the issue as a dup. If it doesn't help please ping and I will reopen.

@dbaeumer dbaeumer added the *duplicate Issue identified as a duplicate of another issue(s) label Mar 29, 2021
@jousby
Copy link
Author

jousby commented Apr 10, 2021

Sorry but that linked issue doesn't help (unless im missing something). I already had the relative path in my .code-workspace file which seems to be the suggested fix (see the commented out line in my code sample above). In my case i had to move away from that to an absolute one to get it to work.

@dbaeumer
Copy link
Member

The linked issue was about the need of confirming the setting. And the example in that issues uses a relative value "eslint.nodePath": ".yarn/sdks". Any idea what would make your repository different?

@gmeligio
Copy link

gmeligio commented May 2, 2021

I'm also having this problem with a relative nodePath. I created a demo project https://github.com/gmeligio/vscode-eslint-yarn-berry-typescript-workspace where the relative path "eslint.nodePath": ".yarn/sdks" doesn't work for a multi-root workspace, but it does work when using a single root workspace. Even resetting/reconfirming the ESlint extension node path and then reloading/relaunching VSCode doesn't fix it in a multi-root workspace. Only setting the absolute path fixes it. Here is the exception that I receive when using the relative path, having the ESlint debug flag enabled.

[Info  - 17:47:46] ESLint server is starting
[Info  - 17:47:46] ESLint server running in node v12.18.3
[Info  - 17:47:46] ESLint server is running.
Uncaught exception received.
Error: spawn C:\Users\User\AppData\Local\Programs\Microsoft VS Code\Code.exe ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

My environment is:

  • Windows 10 21H1 (OS Build 19043.964)
  • VSCode 1.55.2 x64
  • Yarn 2.4.1
  • dbaeumer.vscode-eslint v2.1.20

You can reproduce the exception by cloning the relative-path branch. On the contrary, the master branch works as expected using an absolute path.

@decademoon
Copy link

I'm experiencing this issue too, please reopen.

Only an absolute path for nodePath in the .code-workspace file works.

I can set nodePath in the specific workspace folder .vscode/settings.json and it works there; is that what we have to do now for each workspace folder that wants to use eslint?

@decademoon
Copy link

Ok I just confirmed, it seems the relative path is not being resolved correctly.

If you use a relative path for nodePath in the .code-workspace file then it is resolved relative to each workspace folder, not the .code-workspace file.

So I can set "nodePath": "../../.yarn/sdks" in my .code-workspace file and it works:

.
├── .yarn
├── projects
│   ├── project-a
│   │   └── script.js
│   └── project-b
└── workspace.code-workspace

@dbaeumer
Copy link
Member

Actually this is how VS Code treats these files. This is why a setting in the code-workspace file is resolved relative to the workspace folder it is applied to.

@decademoon
Copy link

Ok it's by design, nevermind.

@jousby
Copy link
Author

jousby commented Jul 16, 2021 via email

@dbaeumer
Copy link
Member

@jousby in a yarn 2 monorepo you usually don't have a code-workspace file? Or do you. Can you explain why this is necessary. Change how these settings are resolved will be a big breaking change and very likely not happening. All I can think of having a different setting in a different scope.

@jousby
Copy link
Author

jousby commented Jul 17, 2021

@dbaeumer The workspace feature in vscode is primarily (for me at least) about making the explorer sidebar easier to navigate (you get a seperate toplevel folder with its own src/, test/ etc for each subproject/package). This is still relevant for monorepo's that are backed by yarn 2. How would you get vscode workspace goodness for yarn 2 monorepos without a code-workspace file?

@dbaeumer
Copy link
Member

dbaeumer commented Aug 5, 2021

I am not sure I understand this. Why can't you simply open the root of the mono repository? This is what I usually do.

@jousby
Copy link
Author

jousby commented Aug 6, 2021

Opening the project at the root and not using the multi root workspace feature will work but... this is a step backwards in user experience.

VSCode has a feature that makes working with monorepo/mult module/multi package projects much nicer. It would be nice not to give this up.

@dbaeumer dbaeumer reopened this Aug 6, 2021
@dbaeumer dbaeumer added feature-request Request for new features or functionality and removed *duplicate Issue identified as a duplicate of another issue(s) labels Aug 6, 2021
@dbaeumer dbaeumer added this to the Backlog milestone Aug 6, 2021
@dbaeumer dbaeumer added the help wanted Issues identified as good community contribution opportunities label Aug 6, 2021
skyuplam added a commit to skyuplam/dotfiles that referenced this issue May 21, 2022
eslint.nodePath only works with absolute paths in multi module vscode workspaces
microsoft/vscode-eslint#1225
@stefan-toubia
Copy link

Support for environment variables in nodePath would be an improvement, at least in my case. This way the shared developer environment can be configurable. Many other vscode settings options support environment variables.

@sorenhoyer
Copy link

sorenhoyer commented Jul 14, 2022

In case anyone comes here because of problems with having their own eslint-config packages bring along their own plugin dependencies in a monorepo setup, then forget about fiddling with resolve-plugins-relative-to (which works on the cli only) and the imo broken implementation in VS Code settings.json which only supports absolute URLs which renders it useless. Instead just install and use @rushstack/eslint-patch https://yarnpkg.com/package/@rushstack/eslint-patch which is as easy as a 1 liner and make it work both from the cli and in VS Code. Even the yarn berry monorepo uses this https://github.com/yarnpkg/berry/blob/master/packages/eslint-config/package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

6 participants