Uh oh!
There was an error while loading. Please reload this page.
src: cache negative results in GetPackageJSON - #56834
Conversation
This change ensures that GetPackageJSON caches which folders do *not* contain a package.json, to prevent excessive file system probing.
ljharb
commented
Jan 30, 2025
What happens if a package.json file is created after this is cached? |
dmichon-msft
commented
Jan 30, 2025
The same thing that happens if you change the content of an existing package.json file after it gets read (and cached). The state of the world as of the first read of the folder is preserved. |
ljharb
commented
Jan 30, 2025
How does one clear the cache, then, after making a change? |
dmichon-msft
commented
Jan 30, 2025
Usually by shutting down and restarting the process, since this cache is used during module loading. |
Missing package.json files were cached in Node <= 20: As near as I can tell, this behavior change was simply an oversight when migrating Node <= 20 also does not provide any means for cache entries regarding |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fixed incorrect negation Co-authored-by: Yagiz Nizipli <yagiz@nizipli.com>
jasnell
commented
Jan 31, 2025
Hmm...as a follow up, should we consider making it possible to clear both the missing and found caches at runtime to allow for hot reloading of these? Would that even make sense? Not something to worry about in this PR but something worth exploring separately. |
nodejs-github-bot
commented
Jan 31, 2025
dmichon-msft
commented
Jan 31, 2025
The entries in the cache will be there because they impacted the loading of already-loaded modules, so you could get some really weird results if we purge the cache and not all of the modules that were loaded from folders whose package.json files were checked. Ultimately, I think any runtime change that affects resolution of already-loaded code is heavily in the "use at your own peril" category. I think we'd be better served ensuring the hits and misses also find their way into the metadata for |
aduh95
commented
Jan 31, 2025
It looks like build is failing on CI |
jasnell
commented
Jan 31, 2025
Appears to need #56846 to land... |
bnoordhuis
commented
Feb 3, 2025
For historic background: I'm the one who first moved package.json reading to C++ land (commits fdbb6dd and 0fdd88a from Nov 2017) and at least back then, missing files were not recorded in the cache. I'm somewhat surprised to learn that has changed because I remember bug reports from people trying to install npm packages at runtime, and, however unwise, we did in fact accommodate such users, IIRC. |
dmichon-msft
commented
Feb 3, 2025
Here's the commit where negative caching was added: |
joyeecheung
commented
Mar 4, 2025
#56846 has landed, so I take that it's time to restart the CI.. |
nodejs-github-bot
commented
Mar 4, 2025
This pull request has been marked as stale due to 210 days of inactivity. |
This pull request has been marked as stale due to 90 days of inactivity. |

Fixes#56821
Ensure that
GetPackageJSONcaches whichpackage.jsonfiles do not exist, not just the contents of the ones that do. In packages with at least one subfolder, it is normal for most folders in a package not to contain apackage.jsonfile, so this will significantly reduce the number of file system reads performed duringGetNearestParentPackageJSON.