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

[2.1.13] Suddenly not resolving modules anymore on working projects #1136

Closed
Friksel opened this issue Dec 10, 2020 · 20 comments
Closed

[2.1.13] Suddenly not resolving modules anymore on working projects #1136

Friksel opened this issue Dec 10, 2020 · 20 comments
Labels
info-needed Issue requires more information from poster

Comments

@Friksel
Copy link

Friksel commented Dec 10, 2020

For some reason the eslint extension cannot find/resolve NONE of the modules anymore on a working project that was finding everything before without issue. It looks like this is a change in the extension I don't know about or an issue.

At first when I saw this I thought I needed to upgrade the eslint package, so I'm at the latest version of eslint now, but without success.

Looking in the Output panel though I see this a weird error thrown by the extension (by eslintServer.js):

Error resolving webpackConfig Error: Cannot find module 'webpack/package.json'

Which makes sense that it cannot find it as my package.json is in the root of the project, as normal, but shouldn't look there in the first place. Not sure why it's searching in some webpack folder the project doesn't even have, but it's obvious that it cannot find it there.

The ESLint label in the bottomright corner is marked with a double checkbox, so it's not blocked or whatever.

[edit] I see that at least v2.1.10, v2.1.8 and v2.1.7, so the previous three versions, have the exact same issue and same error message in the output. But I didn't change anything AFAIK to both the project as well as to the installed modules. I'm at the latest version of VS Code for a while now (1.51.1) and didn't have this problem recently. Also just checked for updates on VS Code but there weren't any.
This was definitely working last week and didn't change anything manually since, so beats me what's going on.

It's now suddenly broken in ALL projects, so definitely not project-related. I'm using the locally installed eslint package on each project.

Something I need to know? Some change in the settings maybe I'm not aware of? Do we need to manually set the location of the package.json now or something? Is this a known issue in the extension?

Further info:

  • Working on Windows 10
  • Vs Code: v1.51.1
  • eslint: v7.15.0 (installed locally in project, no global package available)
  • eslint-plugin-import: v2.22.1
  • eslint-import-resolver-webpack: v0.12.2
@Friksel Friksel changed the title [2.1.13] Suddenly not finding modules anymore on working projects [2.1.13] Suddenly not resolving modules anymore on working projects Dec 10, 2020
@dbaeumer
Copy link
Member

@Friksel does the validation happen correctly when you use eslint in the terminal. If this is the case can you please provide me with a GitHub repository I can clone that demos what you are experiencing.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Dec 11, 2020
@Friksel
Copy link
Author

Friksel commented Dec 13, 2020

@dbaeumer Thanks for your response.

When running pnpx eslint path-to\file.js (the pnpm alternative of npx) in the a terminal eslint executes, but there are no messages in the output (other than the console.log() I put inside the webpack.config.js myself, but repeated several times in a row for some reason).
So that indicates eslint doesn't find an issue.

When I make an error in my javascript and run eslint directly from the command line again it DOES report that error, so eslint is indeed linting.
Also it reports it when I deliberately try to import from a non existing node_modules package. So also the linting on the resolve with running eslint directly passes the test fine as expected and only throws an error when I deliberately enter a non existing node module to resolve from.

So to me it looks like eslint is running fine and the issue isn't in eslint nor its config.

I'm keep on getting the Cannot find module 'webpack/package.json as reported by the vscode-eslint extension though. That seems to be the problem. As the package.json is obviously not inside a non existing webpack folder, but inside the root. And that has always been like that in all my projects.

@dbaeumer
Copy link
Member

@Friksel can you please provider me with a GitHub repository I can clone that demos this.

@dbaeumer
Copy link
Member

Could be a working directory issue. You might want to have a look at the eslint.workingDirectories setting.

@Friksel
Copy link
Author

Friksel commented Dec 14, 2020

@Friksel can you please provider me with a GitHub repository I can clone that demos this.

Sorry, I never send projects for obvious reasons. Also I'm using both webpack as well as eslint setups both pretty standard with webpack and eslint configs in the root of the projectfolder, together with the package.json. And it always worked fine that way (for years). But if you have a particular question I can always look of course.

Could be a working directory issue. You might want to have a look at the eslint.workingDirectories setting.

I don't have that setting set. Never had either. So I would expect the default would be to look for a package.json in the root of the project (as a matter of fact I wonder why it's searching for the package.json), as that's the standard. I could try to set that setting manually, but I'm not sure where to set it too, as I would expect everything to be default.

I've just tried adding the setting like this, but it doesn't help, still the same issues (also tried directory like "." and "", but same result):

"eslint.workingDirectories": [
        { 
            "directory" : "./", 
            "changeProcessCWD": true
        }
    ],

Could you please tell me how to set that setting to have the package.json in the root and confirm that's really necesary if I'm using standard locations for config files? Thanks

@dbaeumer
Copy link
Member

The working directory setting is usually necessary if you have a multi project repository with different configs per folder.

It is hard to say why this is not working for you unless I get a GitHub repository I can look at. If you can share your project could you distil a reproducible case.

@mvirbicianskas
Copy link

Having same issue, previously had this:

"eslint.workingDirectories": [ {  "mode": "auto" } ],

Removing it didn't help, resetting decisions didn't help, reinstalling the extension didn't help.
It seems with newer VSCode versions ESLint doesn't respect .eslintrc.json in the root directory for some reason.
VSCode version: 1.52.0
Node: 12
ESLint version: 2.1.14

@dbaeumer
Copy link
Member

@mvirbicianskas can you please provide me with a GitHub repository I can clone that demos what you are experiencing.

@mvirbicianskas
Copy link

mvirbicianskas commented Dec 15, 2020

hey @dbaeumer apologies, should've started with that, here's public library I just created https://github.com/mvirbicianskas/Eslint Not sure whether it's correct approach to share such stuff?

UPDATE: take note index.ts UNUSED_VAR should be squiggly red-lined in VSCode, but for me it's with lower opacity like a warning of some sort.

Let me know if you have any additional questions

@dbaeumer
Copy link
Member

@mvirbicianskas this works for me as expected

capture

@mvirbicianskas
Copy link

mvirbicianskas commented Dec 15, 2020

@dbaeumer this is weird, I've restarted the editor multiple times and it didn't work, after quitting - it works ¯\(ツ)/¯ except for my project is still not working 😂 but apparently this is not extension's issue.
Sorry for bothering 🙏

UPDATE: in my case it was airbnb overriding some local rules thats why i got confused that some rules were applied and some not leading me into thinking that ESLint doesnt find/respect eslint config and falls back to some defaults.

@Friksel
Copy link
Author

Friksel commented Dec 15, 2020

The working directory setting is usually necessary if you have a multi project repository with different configs per folder.

I don't have a multi-project repository. And so don't have different configs per folder. As said, the config was working fine before for years. Without that setting. Still I've tried the setting, but it didn't help.

It is hard to say why this is not working for you unless I get a GitHub repository I can look at. If you can share your project could you distil a reproducible case.

As I wrote before I never send projects. And it shouldn't be necesary to debug this issue. If you have a thing I can check or have a question I'm happy to look and answer.

It would also be appreciated if you could answer the question I asked you above:

I've just tried adding the setting like this, but it doesn't help, still the same issues (also tried directory like "." and "", but same result):

"eslint.workingDirectories": [
        { 
            "directory" : "./", 
            "changeProcessCWD": true
        }
    ],

Could you please tell me how to set that setting to have the package.json in the root and confirm that's really necesary if I'm using standard locations for config files? Thanks

@dbaeumer
Copy link
Member

The working directory setting you use is basically a noop since using the workspace root is the default. An example on how this setting is supposed to be used is here: https://github.com/microsoft/vscode-eslint#settings-options look for the bullet about eslint.workingDirectories.

Since ESLint depends on so many parameters (version, plugins, configuration files, package.json entries, and eventually webpack configuration and TS configuration files) debugging this does from my experience require an example. Otherwise it is very unlikely that we ever talk about the same setup.

If you can't share your repository publicly you can add my GitHub id to it and I will receive a notification on how to clone it.

@Friksel
Copy link
Author

Friksel commented Dec 15, 2020

The working directory setting you use is basically a noop since using the workspace root is the default.

Why then did you give this advise in the first place? Come on man, read my posts before advising.

Since ESLint depends on so many parameters (version, plugins, configuration files, package.json entries, and eventually webpack configuration and TS configuration files) debugging this does from my experience require an example. Otherwise it is very unlikely that we ever talk about the same setup.

A good developer knows what questions to ask. Requesting a full project from a user to debug an issue in your own extension is pretty lame to me.

Also I already gave you the version numbers in my opening post.

Several times I now asked you to ask questions so I can help you, but you refuse to ask these questions. You obviously don't want to help. I quit helping you debugging the issues in your extension now. You obviously don't want to fix this nor recognise this issue. This is the last post I posted about this as you're wasting my time.

@mvirbicianskas
Copy link

whoa there, @Friksel chill dude. I don't think you're being asked to provide full project repo. See my example above - try to reproduce the issue in a separate repository with as minimal configuration as possible and if it happens that it's really a bug inside the extension you will have to share that minimal reproduced repo here.

@dbaeumer
Copy link
Member

@mvirbicianskas thanks for jumping in. You are correct I don't need the full repository, a distilled version is enough which I tried to point out in this comment #1136 (comment) via

could you distil a reproducible case.

This is also documented in our issue guidlines: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions#writing-good-bug-reports-and-feature-requests

@Friksel ESlint and most of its plugins and configurations resolve files relative to a current working directory. So if ESLint can't find certain files than in many cases the current working directory is not correct. The setting I pointed you too gives you control over the working directory the eslint server is using when validating certain files.

@Friksel
Copy link
Author

Friksel commented Dec 17, 2020

@dbaeumer Doing more testing the issue has to do with the latest version of the Eslint package which was released 12 days ago (or something that stopped working with that version) in combination of npm vs pnpm and the vscode-eslint extension.

When downgrading to an earlier version, I just tested 7.11.0 up to right before 7.14.0, so right before the latest version 7.15.0 (updates also automatically update the packages eslint-config-airbnb-base and eslint-plugin-import with pnpm) the vscode-eslint extension is working fine again. But when upgrading to 7.15.0 again after that it's broke again and visa versa.

Before I never had set the setting "eslint.packageManager", but I just found out about that setting and set it to pnpm like so `"eslint.packageManager": "pnpm". But that doesn't make a difference, and as said, before it was working fine without setting it.

Looking at the change log of eslint 7.15.0 it doesn't seem to be a huge update though, so not sure what's causing this update to let vscode-eslint fail resolving while earlier versions where working fine.

I also notice that eslint 7.15.0 and the vscode-eslint extension DO work when moving the project completely from pnpm to npm instead. So if I completely remove the full node_modules folder and pnpm yaml (pnpm's alternative to the package.lock file) and re-install everything again, but with npm instead of pnpm, eslint and vscode-eslint work as expected and resolve fine even with eslint 7.15.0. But when after that I remove the node_modules folder again and install everything with pnpm again it cannot resolve the modules anymore and vscode-eslint throws the error that it cannot find the module webpack\package.json (which does exist btw; node_modules\webpack (= symlink)\package.json)

This is project dependent though, as all projects here DO work with pnpm and eslint@7.15.0 (and related packages)/ vscode-eslint, except for two projects where all packages have the same versions. And I even did a complete refreshed install with pnpm install after removing both the pnpm yaml-file and the node_modules folder.

I also ran a Eslint: reset library execution decisions to be absolutely sure vscode-eslint uses the locally installed eslint AND picks up the pnpm setting. And after executing that restarted VS Code just to be sure.

But none of this seem to help. The only thing that's directly comes into mind by comparing all projects that work and the two projects that don't is that the non-working projects use the package svgo-sprite-loader . But that shouldn't trigger any issue in a file that's not even using that module I'd say.

@Friksel ESlint and most of its plugins and configurations resolve files relative to a current working directory. So if ESLint can't find certain files than in many cases the current working directory is not correct. The setting I pointed you too gives you control over the working directory the eslint server is using when validating certain files.

Yes, I know that by now. But the working directory IS okay and as I said many times now it always worked too and as you can see in this post it IS working when using NPM and it is even working in the project showing this issue (that was working for years) when switching eslint back to 7.14.0, so one version before the last update which happens to be released exactly 12 days ago.

But I'm talking to a wall here.

@Friksel
Copy link
Author

Friksel commented Dec 17, 2020

Alright. The issue didn't have anything to do with Eslint, nor everything related.

There is an issue in the latest version of the svg-sprite-loader node package; it's trying to execute some internal code to require 'webpack/package.json', but can't find it and so throws an error causing the full vscode-eslint process to stop by this error.
Changing the webpackVersion constant in that module by hand now fixes the issue.

Just found out there are more people with the same issue here:
JetBrains/svg-sprite-loader#417

Not sure why vscode-eslint is more sensitive to this than direct command line eslint though, as that wasn't showing any error nor stopped the process, but at least found the issue now finally.

Sorry for all the inconvience. Closing this issue now.

@Friksel Friksel closed this as completed Dec 17, 2020
@dbaeumer
Copy link
Member

dbaeumer commented Jan 5, 2021

I am happy to hear that you could solve the issue.

@quoyi
Copy link

quoyi commented Feb 8, 2021

Alright. The issue didn't have anything to do with Eslint, nor everything related.

There is an issue in the latest version of the svg-sprite-loader node package; it's trying to execute some internal code to require 'webpack/package.json', but can't find it and so throws an error causing the full vscode-eslint process to stop by this error.
Changing the webpackVersion constant in that module by hand now fixes the issue.

Just found out there are more people with the same issue here:
JetBrains/svg-sprite-loader#417

Not sure why vscode-eslint is more sensitive to this than direct command line eslint though, as that wasn't showing any error nor stopped the process, but at least found the issue now finally.

Sorry for all the inconvience. Closing this issue now.

You are my hero! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants