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

[BUG] npm version fails when using --include-workspace-root with no root package.json name #5580

Closed
2 tasks done
msrose opened this issue Sep 23, 2022 · 1 comment
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@msrose
Copy link

msrose commented Sep 23, 2022

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Running npm version <inc> --include-workspace-root --workspaces throws npm ERR! Cannot read properties of undefined (reading '0') if the workspace root doesn't have a name field in its package.json.

Expected Behavior

The version command should not throw an error if the workspace root doesn't have a name field.

Steps To Reproduce

package.json:

{
  "workspaces": [
    "packages/*"
  ],
  "version": "1.3.0"
}

packages/one/package.json:

{
  "name": "one",
  "version": "1.3.0"
}

Running npm version minor --include-workspace-root --workspaces gives the following error:

undefined
v1.4.0
one
v1.4.0
npm ERR! Cannot read properties of undefined (reading '0')

Upon adding a name field to the workspace root, the command succeeds:

package.json:

{
  "name": "root",
  "workspaces": [
    "packages/*"
  ],
  "version": "1.4.0"
}

npm version minor --include-workspace-root --workspaces:

root
v1.5.0
one
v1.5.0

Environment

  • npm: 8.19.2
  • Node.js: v16.17.0
  • OS Name: macOS Monterey 12.5.1
  • System Model Name: Macbook Pro
  • npm config:
; node bin location = /Users/msrose/.nvm/versions/node/v16.17.0/bin/node
; node version = v16.17.0
; npm local prefix = /Users/msrose/test-stuff/test-npm-bug
; npm version = 8.19.2
; cwd = /Users/msrose/test-stuff/test-npm-bug
; HOME = /Users/msrose
@msrose msrose added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Sep 23, 2022
@wraithgar
Copy link
Member

the name field is required in the package.json. The docs are not currently consistent about this, but there is an issue open to clean that up npm/documentation#134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

2 participants