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

why is there a package.json export for package.json? #1

Closed
dagda1 opened this issue Mar 3, 2022 · 1 comment
Closed

why is there a package.json export for package.json? #1

dagda1 opened this issue Mar 3, 2022 · 1 comment

Comments

@dagda1
Copy link

dagda1 commented Mar 3, 2022

Hi,

Apologies if this is the wrong place to ask but I wonder if it would be possible to explain why package.json is included in the exports?

{
  "exports": {
    ".": "./dist/index.js",
    "./*": "./dist/components/*/index.js",
    "./styles": "./dist/styles/index.css",
    "./styles/*": "./dist/styles/*/index.css",
    "./package.json": "./package.json"
  },
}
@ctjlewis
Copy link
Member

ctjlewis commented Mar 11, 2022

So, weirdly, there are bundlers that would throw when trying to interop between ESM and CJS if package.json was not manually specified this way in conditional exports. This field is meant to prevent that from happening at all. I think the last context I saw it in was React Native with Metro as the bundler.

This will also allow for import pkgJson from "my-package/package.json" assert { type: "json" } out of the box when Node supports it.

See:

@ctjlewis ctjlewis pinned this issue Mar 11, 2022
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

No branches or pull requests

2 participants