[rush] Rush add causes malformed package.json if the package.json does not have "dependencies" field yet and have >1 entries in "contributors" field #4811
If there are >1 contributors in package.json and there is no dependencies yet, running rush add --package <pkg-name> will cause the package.json to be malformed.
β pkg-a git:(master) β rush add --package meow
Found configuration in /path/to/repo/rush-repro-rush-add/rush.json
Rush Multi-Project Build Tool 5.124.6 - https://rushjs.io
Node.js version is 18.20.3 (LTS)
Found configuration in /path/to/repo/rush-repro-rush-add/rush.json
Starting "rush add"
Determining new version for dependency: meow
No version selector was specified, so the version will be determined automatically.
Trying to acquire lock for pnpm-8.15.8
Acquired lock for pnpm-8.15.8
Found pnpm version 8.15.8 in /path/to/user/.rush/node-v18.20.3/pnpm-8.15.8
Symlinking "/path/to/repo/rush-repro-rush-add/common/temp/pnpm-local"
--> "/path/to/user/.rush/node-v18.20.3/pnpm-8.15.8"
The "ensureConsistentVersions" policy is NOT active, so we will assign the latest version.
Querying NPM registry for latest version of "meow"...
Found latest version: 13.2.0
Assigning version "~13.2.0" for "meow".
Updating projects to use meow@~13.2.0
Wrote/path/to/repo/rush-repro-rush-add/pkg-a/package.json
Running "rush update"
Checking Git policy for this repository.
Trying to acquire lock for pnpm-8.15.8
Acquired lock for pnpm-8.15.8
Found pnpm version 8.15.8 in /path/to/user/.rush/node-v18.20.3/pnpm-8.15.8
Symlinking "/path/to/repo/rush-repro-rush-add/common/temp/pnpm-local"
--> "/path/to/user/.rush/node-v18.20.3/pnpm-8.15.8"
Transforming /path/to/repo/rush-repro-rush-add/common/config/rush/.npmrc
--> "/path/to/repo/rush-repro-rush-add/common/temp/.npmrc"
Updating workspace files in /path/to/repo/rush-repro-rush-add/common/temp
Copying "/path/to/repo/rush-repro-rush-add/common/config/rush/pnpm-lock.yaml"
--> "/path/to/repo/rush-repro-rush-add/common/temp/pnpm-lock.yaml"
Copying "/path/to/repo/rush-repro-rush-add/common/config/rush/pnpm-lock.yaml"
--> "/path/to/repo/rush-repro-rush-add/common/temp/pnpm-lock-preinstall.yaml"
Checking installation in "/path/to/repo/rush-repro-rush-add/common/temp"
Deleting files from /path/to/repo/rush-repro-rush-add/common/temp/node_modules
Running "pnpm install" in /path/to/repo/rush-repro-rush-add/common/temp
βERR_PNPM_JSON_PARSEβ Unexpected token "}" (0x7D) in JSON at position 287 while parsing near "...meow\": \"~13.2.0\",\n }\n}\n" in /path/to/repo/rush-repro-rush-add/pkg-a/package.json
15 | "dependencies": {
16 | "meow": "~13.2.0",
> 17 | }
| ^
18 | }
19 |
The command failed:
/path/to/repo/rush-repro-rush-add/common/temp/pnpm-local/node_modules/.bin/pnpm install --store /path/to/repo/rush-repro-rush-add/common/temp/pnpm-store --config.cacheDir=/path/to/repo/rush-repro-rush-add/common/temp/pnpm-store --config.stateDir=/path/to/repo/rush-repro-rush-add/common/temp/pnpm-store --no-prefer-frozen-lockfile --no-strict-peer-dependencies --config.auto-install-peers=false --config.resolutionMode=highest --config.ignoreCompatibilityDb --recursive --link-workspace-packages false --reporter default
ERROR: Error: The command failed with exit code 1
Giving up after 1 attempts
ERROR: The command failed with exit code 1
Details
Standard questions
Please answer these questions to help us investigate your issue more quickly:
Summary
If there are >1 contributors in package.json and there is no dependencies yet, running
rush add --package <pkg-name>
will cause the package.json to be malformed.Repro steps
https://github.com/kenrick95/rush-repro-rush-add-malformed-package-json
Check
pkg-a/package.json
:Repro:
Expected result:
Actual result:
Details
Standard questions
Please answer these questions to help us investigate your issue more quickly:
@microsoft/rush
globally installed version?rushVersion
from rush.json?useWorkspaces
from rush.json?node -v
)?