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

Is name actually optional? #9

Open
Ethan-Arrowood opened this issue Feb 12, 2024 · 8 comments
Open

Is name actually optional? #9

Ethan-Arrowood opened this issue Feb 12, 2024 · 8 comments

Comments

@Ethan-Arrowood
Copy link
Collaborator

As mentioned here, there is reason to believe that the name property is not actually optional in practice.

More research should be done regarding npm cli's usage of the property in various commands. If the lack of the name property causes anything but publishing to fail we must document that behavior.

@ljharb
Copy link
Member

ljharb commented Feb 12, 2024

In particular, I suspect workspaces, npm link, npm ls, npm explain, are worth looking into.

@rotu
Copy link
Contributor

rotu commented Aug 19, 2024

FYI, I have seen version omitted when a package.json exists only to influence node behavior via "type": "module" / "commonjs".

Node's docs seem to suggest this usage is kosher:
https://nodejs.org/api/packages.html#writing-dual-packages-while-avoiding-or-minimizing-hazards

If you have a dist/esm and dist/cjs folder and you want to keep the .js suffix, there doesn't seem to be a good way around it.

@ljharb
Copy link
Member

ljharb commented Aug 19, 2024

At a project root, name and version are required; since all commands are meant to run in a project root, this works out fine. Indeed nested package.json files with only “type” or “main” are fine and expected.

@mcollina
Copy link
Member

name is mostly required, but I use package.json without it very often. It'd be odd to add names in those cases.

@wesleytodd
Copy link
Collaborator

I think for the sake of these docs we should elaborate on when it is required and when it is not. The goal is to educate and document, not to propose making it required when it is not actually required in all situations.

@Ethan-Arrowood
Copy link
Collaborator Author

Agreed - keep in mind that this documentation is not a specification. It may eventually lead to one someday, but for now we are solely focussed on documenting how things currently work across (the ever growing) JavaScript ecosystem.

@rotu
Copy link
Contributor

rotu commented Aug 21, 2024

Yeah, I think any sort of description of package.json has to be with respect to a tool. So the question “is name actually optional?” is underspecified.

For instance, name is required by npm but not required by node. Other tools (pnpm, yarn, deno, bun, esbuild, SchemaStore…) have diverging expectations.

@wesleytodd
Copy link
Collaborator

Ideally we could make a compelling case for all of those projects to come together here to build our the right links or docs for folks doing cross ecosystem work.

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

5 participants