Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export package.json from exports list in package.json to support introspection by build tools #7865

Closed

Conversation

JimAllanson
Copy link

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 access package.json via require(), resulting in an error Package 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 read package.json, or even the suggestion that node itself should allow requiring of package.json without an explicit export. However, the pattern of adding package.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

@apollo-cla
Copy link

@JimAllanson: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link

netlify bot commented Apr 4, 2024

👷 Deploy request for apollo-server-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 25c962d

Copy link

codesandbox-ci bot commented Apr 4, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@JimAllanson JimAllanson closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants