Add ./package.json
as an export entry
#1109
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will avoid breaking older tools that try to read
package.json
files from packages using package name instead of absolute path.Because when
exports
is set, accessing files that's not specified in theexports
property is not allowed by node and it will throw aERR_PACKAGE_PATH_NOT_EXPORTED
error (rightly so).This easily reproducible in the
node
repl.This will throw
This will not throw
Something similar has been mentioned in this great article https://blog.isquaredsoftware.com/2023/08/esm-modernization-lessons/#issue-history by @markerikson (sorry for the ping, feel free to ignore) when he worked on modernizing
@reduxjs/toolkit
(which depends onimmer
and this is how I found the issue)Similar issues in the wild on GitHub for
Package subpath './package.json' is not defined by "exports"
https://github.com/search?q=%22Package+subpath+%27.%2Fpackage.json%27+is+not+defined+by+%22exports%22%22&type=issues