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

Bug: Long node_modules plugin paths cannot be found on Windows #17763

Closed
1 task
karlhorky opened this issue Nov 15, 2023 · 6 comments
Closed
1 task

Bug: Long node_modules plugin paths cannot be found on Windows #17763

karlhorky opened this issue Nov 15, 2023 · 6 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features repro:yes

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Nov 15, 2023

Environment

Node version: 20.9.0
npm version: 10.1.0
Local ESLint version: 8.53.0
Global ESLint version: --
Operating System: Microsoft Windows Server 2022 10.0.20348

What parser are you using?

Default (Espree)

What did you do?

Configuration (Flat Config)
import eslintImport from 'eslint-plugin-import';

const config = [
  {
    plugins: {
      import: eslintImport,
    },
    rules: {
      'no-unused-vars': 'warn',
    },
  },
];

export default config;
const a = 1;

What did you expect to happen?

ESLint should run, also when the paths are deep and long (over 260 character MAX_PATH limit on Windows)

What actually happened?

ESLint crashes on Windows when the paths are deep and long (over 260 character MAX_PATH limit on Windows)

$ npm install
$ npx eslint .  # In root, working
D:\a\eslint-max_path-windows-bug\eslint-max_path-windows-bug\index.js
Warning:   1:7  warning  'a' is assigned a value but never used  no-unused-vars

$ mkdir long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\
$ cp eslint.config.js long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\
$ cp index.js long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\
$ cp package.json long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\

$ cd long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\
$ npm install
$ npx eslint .

Oops! Something went wrong! :(

ESLint: 8.53.0

Error: Cannot find package 'D:\a\eslint-max_path-windows-bug\eslint-max_path-windows-bug\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\node_modules\eslint-plugin-import\package.json' imported from D:\a\eslint-max_path-windows-bug\eslint-max_path-windows-bug\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\eslint.config.js
Did you mean to import eslint-plugin-import/lib/index.js?
    at legacyMainResolve (node:internal/modules/esm/resolve:189:26)
    at packageResolve (node:internal/modules/esm/resolve:[7](https://github.com/karlhorky/eslint-max_path-windows-bug/actions/runs/6876786397/job/18703094495#step:9:8)76:14)
    at moduleResolve (node:internal/modules/esm/resolve:[8](https://github.com/karlhorky/eslint-max_path-windows-bug/actions/runs/6876786397/job/18703094495#step:9:9)38:20)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:3[9](https://github.com/karlhorky/eslint-max_path-windows-bug/actions/runs/6876786397/job/18703094495#step:9:10))
    at link (node:internal/modules/esm/module_job:84:36)

The D:\a\eslint-max_path-windows-bug\eslint-max_path-windows-bug\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\node_modules\eslint-plugin-import\package.json path is 277 characters long.

Alternatives Considered

I was first thinking this may be a Windows configuration problem or a Node.js path resolution bug, but apparently both of these support 260+ character paths:

Link to Minimal Reproducible Example

https://github.com/karlhorky/eslint-max_path-windows-bug

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

This is a contrived example, but this can happen easily in normal projects with tools like pnpm, which creates long file paths:

@mdjermanovic
Copy link
Member

mdjermanovic commented Nov 15, 2023

I can reproduce this locally. However, it doesn't look like a problem in ESLint, but rather in Node.js, and I'm not sure if there's anything we could do in ESLint to avoid this.

The error message says:

Cannot find package ...\node_modules\eslint-plugin-import\package.json imported from ...\eslint.config.js.

ESLint just calls import() with the path of the eslint.config.js file, which seems to be resolved successfully as it executes. ESLint doesn't resolve any paths inside eslint.config.js, it's Node.js that loads and executes it and resolves its imports. I'm getting the same error when I run the module directly (node eslint.config.js).

@mdjermanovic mdjermanovic added the core Relates to ESLint's core APIs and features label Nov 15, 2023
@karlhorky
Copy link
Contributor Author

Interesting, so maybe the comment by @bzoz that Node.js is not affected by the 260 character path limit on Windows doesn't apply here or is outdated somehow - maybe Node.js has a limitation here...

Maybe time to open a Node.js bug.

@karlhorky
Copy link
Contributor Author

karlhorky commented Nov 16, 2023

I opened a first issue to revisit Microsoft's MAX_PATH explanation and workarounds guide in case anything has changed with Node.js support for long 260+ character paths on Windows, also in light of LongPathsEnabled:

@karlhorky
Copy link
Contributor Author

@nzakas
Copy link
Member

nzakas commented Nov 17, 2023

To echo @mdjermanovic, this is an issue with Node.js rather than with ESLint, so closing.

@nzakas nzakas closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
@karlhorky
Copy link
Contributor Author

karlhorky commented Apr 5, 2024

These file/folder structures that have long paths are commonly created by pnpm as well - if you're running into "Cannot find file" with ESLint and pnpm on Windows and are looking for a workaround, here's what I'm currently using:

This is just a temporary workaround until the Node.js PR fixing long paths on Windows is merged:

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators May 16, 2024
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features repro:yes
Projects
Archived in project
Development

No branches or pull requests

3 participants