Export package.json from exports list in package.json to support introspection by build tools #7865
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.
A common pattern in build tooling such as bundlers is to introspect the
package.json
file for dependencies. By providing an exports field in the package.json, external tools are prevented from being able to accesspackage.json
viarequire()
, resulting in an errorPackage subpath './package.json' is not defined by "exports"
.This change would add
package.json
to the list of exports, allowing it to be required in this manner.This does appear to be some debate around this issue, and whether it's best solved by packages adding
package.json
to their exports list, by build tools being more robust against this scenario and falling back to e.g.fs
APIs to readpackage.json
, or even the suggestion that node itself should allow requiring ofpackage.json
without an explicit export. However, the pattern of addingpackage.json
to the exports appears to be fairly commonly accepted.Further context can be found here:
nodejs/node#33460
uuidjs/uuid#444
uuidjs/uuid#449
(In my specific case, I'm encountering this issue when trying to package a service that uses Apollo server for AWS Lambda, using esbuild with the Datadog esbuild plugin