Skip to content

module: report unreadable package.json - #65223

Open
bitpshr wants to merge 1 commit into
nodejs:mainfrom
bitpshr:module/unreadable-package-json
Open

module: report unreadable package.json#65223
bitpshr wants to merge 1 commit into
nodejs:mainfrom
bitpshr:module/unreadable-package-json

Conversation

@bitpshr

@bitpshr bitpshr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #65220. A package.json that exists but cannot be read was treated as absent, so exports and type silently disappeared and a specifier could resolve to a different file than the package declares. An unparsable package.json already throws ERR_INVALID_PACKAGE_CONFIG, so this makes the unreadable case consistent: ENOENT and ENOTDIR still mean "no package config here", anything else reports the underlying error.

Two alternatives if you'd prefer them: warn and keep resolving, or restrict the new error to the direct package lookup and stay silent while walking up for the nearest parent config. That second one matters if anyone relies on resolution succeeding past an unreadable package.json in an ancestor directory. Happy to change course on either.

Fixes: #65220

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Aug 11, 2026
A package.json that exists but cannot be read was treated the same as
one that is not there: the read failure returned no config and
resolution continued as if the package had none. Fields such as
"exports" and "type" silently disappear, so a specifier can resolve to
a different file than the package declares, while an unparsable
package.json already throws ERR_INVALID_PACKAGE_CONFIG.

Keep treating ENOENT and ENOTDIR as "no package config here", and
report any other read failure with the underlying error.

Fixes: nodejs#65220
Signed-off-by: Paul Bouchon <mail@bitpshr.net>
@guybedford

Copy link
Copy Markdown
Contributor

It could be worth checking what error used to be thrown here before the resolver was refactored into C++, as I'm pretty sure this did used to throw an error, it just clearly didn't have coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESM resolver treats an unreadable package.json as absent: exports silently vanish and the wrong file can load

3 participants