Repository navigation
Long node_modules paths cannot be found on Windows when LongPathsEnabled enabled #50753
Copy link
Copy link
Labels
pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
Description
Version
v20.9.0
Platform
Microsoft Windows NT 10.0.20348.0 x64
Subsystem
No response
What steps will reproduce the bug?
I created a reproduction repo at https://github.com/karlhorky/node-js-max_path-windows-bug . The steps in the GitHub Actions workflow file reproduce the bug:
# Test whether Windows support for long paths is enabled
(Get-ItemProperty "HKLM:System\CurrentControlSet\Control\FileSystem").LongPathsEnabled
# 1
# Clone, setup Node.js
# Install dependencies with npm
npm install
# Run program in short path (✅ works)
node eslint.config.js
# Make directory with long path and copy all files there
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\
# Change to directory with 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\
# Install dependencies with npm
npm install
# Run program in long path (💥 crashes)
node eslint.config.jsThe error that shows up is this:
node:internal/process/esm_loader:[4](https://github.com/karlhorky/node-js-max_path-windows-bug/actions/runs/6890011394/job/18742165029#step:11:5)0
internalBinding('errors').triggerUncaughtException(
^
Error: Cannot find package 'D:\a\node-js-max_path-windows-bug\node-js-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\node-js-max_path-windows-bug\node-js-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:776:14)
at moduleResolve (node:internal/modules/esm/resolve:838: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:3[5](https://github.com/karlhorky/node-js-max_path-windows-bug/actions/runs/6890011394/job/18742165029#step:11:6)2:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:3[6](https://github.com/karlhorky/node-js-max_path-windows-bug/actions/runs/6890011394/job/18742165029#step:11:7)) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v20.[9](https://github.com/karlhorky/node-js-max_path-windows-bug/actions/runs/6890011394/job/18742165029#step:11:10).0
Error: Process completed with exit code 1.
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
If Windows support for long paths is turned on (see LongPathsEnabled check above showing that it's enabled) I would expect Node.js to also support long paths (longer than the Windows ~260 characters MAX_PATH limit)
What do you see instead?
The crash and error above
Additional information
More information about LongPathsEnabled :
Context:
I'm here after originally reporting the bug in ESLint (I thought that this comment by @bzoz meant that Node.js is not affected by the 260 character path limit on Windows :
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
Activity
MrJithil commentedon Nov 17, 2023
cc: @nodejs/platform-windows
StefanStojanovic commentedon Nov 17, 2023
I took a look at it, but found another issue instead. @karlhorky I forked your repo and the failing run can be found here.
I made long path longer, because the original one was shorter then 260 characters. After I did it, Even running
npm install(or anything else, example here) started failing. Since I'm seeing same error regardless if I'm using CMD or PowerShell it seems safe to assume this is something Windows specific.Back to the issue you reported, importer uses file URLs internally, thus cannot use
\\?\prefix required for handling long paths. I'll investigate this further, and add another comment based on my findings.karlhorky commentedon Nov 17, 2023
Thanks for the response, and for the investigation! 🙌
I guess you mean "anything else Node.js-related"? Because the
cpcommand on the previous step doesn't fail:But maybe the way that GitHub Actions is launching PowerShell + CMD has a problem - maybe a separate GitHub Actions-related problem cc @al-cheb @MaksimZhukov @chrispat:
I'll try to run various commands from a directory with a long path on my Windows machine locally and see what I find.
karlhorky commentedon Nov 17, 2023
Ok, I ran some commands on a Windows 11 Pro x64 machine (both
nodeand alsocmd) I can confirm that running commands from within deep directories fails withThe directory name is invalid:Commands like
cdstill work:cmd.exealso doesn't run:Also when running
C:\Windows\System32\cmd.exewith the full path - still has a problem with the current directory being invalid:Wonder if someone from the Windows team involved in interop / this
MAX_PATHlimitation could confirm that running - I don't know of contacts who work on the Windows team, but maybe @JeremyKuhne (because of this blog post) or @iSazonov (because of involvement in PowerShell/PowerShell#17197 and PowerShell/PowerShell#13955) or @SteveL-MSFT (because ofPowerShell/PowerShellinvolvement) ?Anyway, back to the import / long path file reading issue, maybe at least this part could be supported by Node.js...
StefanStojanovic commentedon Nov 20, 2023
That is correct.
cpis a command, not an executable, so I assume only applications are facing that issue.Back to the import with long paths problem. Investigating a bit longer got me to one of my first PRs in this repo, especially to changes in the manifest file. Applying that change solved an issue for me, but I'd like to investigate a bit more to find the root cause. The original PR was dropped in favor of this one as that was enough to fix the issue and something similar should probably be possible here. I'll get back to this later this week to continue my work.
karlhorky commentedon Nov 21, 2023
Regarding the "PowerShell unable to launch programs from long path" problem:
I've commented in an existing
MAX_PATHissue in thePowerShell/PowerShellrepo:I may need to open a new issue for this as well.
StefanStojanovic commentedon Dec 5, 2023
After further investigation, I saw that some parts of the code responsible for module loading, do not add the required
\\?\prefix for Windows long path support. I was able to make a PoC fixing it without the changes to the manifest file, but that's just a starting point for further work.11 remaining items
StefanStojanovic commentedon May 21, 2024
@karlhorky we can do it both ways. I do not have time to work on this now, but I've talked to my colleague @huseyinacacak-janea and he'll take a look.
In my PR that addressed this issue, I added a new test
test/es-module/test-GH-50753.js, which passes without any problems. Do you see some way to change that test and make it experience same issue you are facing with GitHub Action in your repo?karlhorky commentedon May 21, 2024
Ok great, thanks for the info!
I see the current version of the test at
test/es-module/test-GH-50753.jshere:node/test/es-module/test-GH-50753.js
Lines 1 to 42 in 2aaeaa8
Current version looks good, but low-level (whereas my reproduction was more on the "end to end" / "integration" end of the spectrum) - maybe there is something else in Node.js that is also failing... 🤔
karlhorky commentedon May 21, 2024
@huseyinacacak-janea could you reopen this issue as a tracking issue for this work?
karlhorky commentedon May 22, 2024
Oh, apparently @huseyinacacak-janea doesn't have access to reopen the issue
@StefanStojanovic could you do it instead?
WangJincheng4869 commentedon May 23, 2024
Can it be merged into other TLC versions?
module,win: fix long path resolve
karlhorky commentedon Sep 9, 2024
@huseyinacacak-janea thanks for the PR fixing the problem in #53294, and thanks @RafaelGSS and other Node.js contributors for the Node.js 22.7.0 release PR #54452 where the fix landed
I just upgraded to Node.js 22.7.0 in my reproduction repo in the PR below:
I can confirm that the workflow run of the GitHub Actions workflow was successful 🎉
So for my reproduction case, this is now resolved 🙌
If there are any other further long path issues with Node.js on Windows, I'll be sure to open a different issue and mention it here (if the issue is not locked over time).
ibrahimqasim-abtrace commentedon Oct 17, 2024
@karlhorky
I tried to follow this fix, and it seemed to work. However, trying longer paths still causes this to fail. In your example, the path length is still below 260. If you try creating a path that is longer than 260 and
npm initin there, what happens then?karlhorky commentedon Oct 18, 2024
@ibrahimqasim-abtrace I have not noticed any failures, but it's possible that I'm not testing the same way you mean.
Can you fork my repo and create a reproduction that fails on GitHub Actions?
https://github.com/karlhorky/node-js-max_path-windows-bug
Then it will be a clear, reproducible failure that Node.js can look at.
Remove .npmrc workaround for Windows long path