npm / npm/cli

[BUG] bad error npm ci with bad package.json

Open
#3,976 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

i have a trailing comma in a json object in a package.json

running npm install prints this:

npm ERR! code EJSONPARSE
npm ERR! path /usr/origami/package.json
npm ERR! JSON.parse Unexpected token "}" (0x7D) in JSON at position 703 while parsing near "honk'\",\n  },\n  \"repository\": {..."
npm ERR! JSON.parse Failed to parse JSON data.
npm ERR! JSON.parse Note: package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR!     /usr/large.rabbit/.npm/_logs/2021-11-02T17_42_41_387Z-debug.log

running npm ci prints this

npm ERR! The `npm ci` command can only install with an existing package-lock.json or
npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
npm ERR! later to generate a package-lock.json file, then try again.

npm ERR! A complete log of this run can be found in:
npm ERR!     /usr/large.rabbit/.npm/_logs/2021-11-02T17_42_36_923Z-debug.log
Expected Behavior

npm ci should print the helpful message like npm install

Steps To Reproduce
  1. have a trailing comma in a json object in a package.json
  2. run npm ci
Environment
  • OS: don't know
  • Node: 16
  • npm: 8.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with a malformed package.json containing a trailing comma, then compare the npm ci and npm install error paths. The change is done when npm ci reports the helpful JSON parse message shown for npm install; no source file or test is identified in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.