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

doc: clarify required-ness of "name" and "version" in package.json files #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eemeli
Copy link

@eemeli eemeli commented Jun 9, 2022

The current content of the Creating a package.json file page indicates that the "name" and "version" fields are always required

A package.json file must contain "name" and "version" fields.

whereas the actual package.json docs page clarifies this with:

If you don't plan to publish your package, the name and version fields are optional.

This minor difference is causing some friction with e.g. Webpack making an assumption based on the former page, resulting in webpack/webpack#13457.

It would be good to get this specified; this PR attempts to do so with (hopefully!) sufficiently simple language.

@ljharb
Copy link
Contributor

ljharb commented Jun 10, 2022

I think npm itself actually always requires these fields, whether the package is published or not.

@eemeli
Copy link
Author

eemeli commented Jun 10, 2022

@ljharb npm requires them in the package's top-level package.json, but does not require them for package.json files that are in its subdirectories. The usage pattern that triggers this is the one documented here: https://nodejs.org/api/packages.html#type

This is useful in particular when a package transpiles TS into JS and provides both CJS and ESM endpoints: microsoft/TypeScript#18442 (comment).

@ljharb
Copy link
Contributor

ljharb commented Jun 10, 2022

I agree, but the package being published or not isn't the discriminator - it's required in any package, including a private:true one.

@eemeli
Copy link
Author

eemeli commented Jun 11, 2022

I'm not completely sure about "name", but "version" is certainly optional when a package.json includes "private": true. I use that often in e.g. documentation, when including such as npm workspaces in a monorepo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Issues or PRs related to the content of the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants