You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ npm install
up to date in 111ms
found 0 vulnerabilities
$ cat package.json
{}
npm exits with code 0 and rewrites the package.json to {}
Running same scenario with npm@v6.14.8 - npm has the expected behaviour: exits with non-zero code and does not change package.json content
$ npm --version
6.14.8
$ npm install
npm ERR! code EJSONPARSE
npm ERR! file /home/coridyn/npm7-workspace-test/temp/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token } in JSON at position 84 while parsing near '...h": "^4.17.20",
npm ERR! JSON.parse }
npm ERR! JSON.parse }
npm ERR! JSON.parse '
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/coridyn/.npm/_logs/2020-10-01T08_09_28_903Z-debug.log
Reify was rewiriting contents of a malformed package.json. This
changeset fixes the problem by making sure build-ideal-tree properly
throws when finding EJSONPARSE errors from the root package.json
Fixes: npm/cli#1883
Current Behavior:
If you have
package.json
with invalid/malformed JSON.Running
npm install
deletes the contents ofpackage.json
and exits successfully with code 0.package.json is rewritten to just be an empty JSON object
{}
, potentially losing data.Expected Behavior:
npm should exit with a non-zero code and should not replace the contents of package.json.
Steps To Reproduce:
With this invalid JSON in package.json (note the invalid trailing comma in dependencies)
Run these commands:
npm exits with code 0 and rewrites the package.json to
{}
Running same scenario with npm@v6.14.8 - npm has the expected behaviour: exits with non-zero code and does not change package.json content
Environment:
This occurs in both Windows and Linux
The text was updated successfully, but these errors were encountered: