Skip to content

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

Closed
eemeli wants to merge 1 commit into
npm:mainfrom
eemeli:published-package-json
Closed

doc: clarify required-ness of "name" and "version" in package.json files#134
eemeli wants to merge 1 commit into
npm:mainfrom
eemeli:published-package-json

Conversation

@eemeli

@eemeli eemeli commented Jun 9, 2022

Copy link
Copy Markdown

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

ljharb commented Jun 10, 2022

Copy link
Copy Markdown
Contributor

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

@eemeli

eemeli commented Jun 10, 2022

Copy link
Copy Markdown
Author

@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

ljharb commented Jun 10, 2022

Copy link
Copy Markdown
Contributor

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

eemeli commented Jun 11, 2022

Copy link
Copy Markdown
Author

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.

@npm npm deleted a comment from npm-docs-robot Aug 12, 2022
@npm npm deleted a comment from npm-docs-robot Aug 12, 2022
@lukekarrys lukekarrys closed this Aug 12, 2022
@lukekarrys lukekarrys reopened this Aug 12, 2022
@darcyclarke darcyclarke added the content Issues or PRs related to the content of the docs label Nov 7, 2022
@kenshanta

Copy link
Copy Markdown
Contributor

Is there a plan to merge/close this PR?

@wraithgar

Copy link
Copy Markdown
Contributor

I'm gonna close this in the interest of erroring on the side of being less confusing. While version is technically not required for private packages that aren't being installed into another directory, trying to explain that subtle distinction is more confusing that saying they're required.

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.

7 participants