日本語

Fixing npm install EJSONPARSE Error

​​npm​JSON,Node.js,Troubleshooting

If npm install shows npm error code EJSONPARSE, package.json is not valid JSON. Look at the line and column in the message, such as (line 6 column 3), and fix the extra or missing comma or the comment near that spot. The error goes away after that.

This is for the case where you added dependencies or a scripts section to package.json by hand, and then npm install or npm run build stopped in the terminal. In my test environment, I caused the error with three typing mistakes: an extra comma, a missing comma, and a comment. Below are the messages I got and the steps until npm install succeeded.

Note

The test environment was Ubuntu 24.04 with Node.js 22.23.4 (npm 10.9.9). I also ran the tests with npm 9.9.4 to see the form where lines begin with npm ERR!. The English message text comes from JSON.parse in Node.js. I did not test other Node.js versions, macOS or Windows, or yarn or pnpm. In the output in this article, I replaced the test folder with /path/to/my-app and the log file location with ~/.npm/_logs/….

When a comma is left after the last item

This is a package.json with a comma left after the last item in dependencies (the numbers on the left are line numbers).

console
$ cat -n package.json
     1	{
     2	  "name": "my-app",
     3	  "version": "1.0.0",
     4	  "dependencies": {
     5	    "is-number": "7.0.0",
     6	  }
     7	}

When I ran npm install in this folder, npm 10.9.9 stopped with the following output (exit code 1. All the errors below also had exit code 1).

console
$ npm install
npm error code EJSONPARSE
npm error path /path/to/my-app/package.json
npm error JSON.parse Expected double-quoted property name in JSON at position 92 (line 6 column 3) while parsing near "...number\": \"7.0.0\",\n  }\n}\n"
npm error JSON.parse Failed to parse JSON data.
npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T15_26_30_254Z-debug-0.log

Expected double-quoted property name means that a property name in double quotes was expected here. After a comma, another property should follow, but line 6, column 3 has }, so JSON.parse stopped reading there. The text after while parsing near shows the characters near the mistake (\n is a line break).

After the failure, the folder contained only package.json. There was no node_modules and no package-lock.json.

When a comma is missing between items

This time I removed the comma at the end of line 3, "version": "1.0.0".

console
$ cat -n package.json
     1	{
     2	  "name": "my-app",
     3	  "version": "1.0.0"
     4	  "dependencies": {
     5	    "is-number": "7.0.0"
     6	  }
     7	}
$ npm install
npm error code EJSONPARSE
npm error path /path/to/my-app/package.json
npm error JSON.parse Expected ',' or '}' after property value in JSON at position 45 (line 4 column 3) while parsing near "...version\": \"1.0.0\"\n  \"dependencies\": {\n  ..."
npm error JSON.parse Failed to parse JSON data.
npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T15_26_30_515Z-debug-0.log

Expected ',' or '}' after property value means that a comma or } was expected after the property value.

Point

If a package.json has one item per line and a comma is missing, the line in the message points to the line after the missing comma, not to the line that lacks it. In this example, the comma is missing from line 3, but the message said line 4 column 3 (the start of "dependencies"). If the line in the message looks correct, check the end of the line before it.

Running npm run build on the same package.json also stopped with EJSONPARSE. This time there was no path line, and the same content followed Invalid package.json: JSONParseError:.

console
$ npm run build
npm error code EJSONPARSE
npm error JSON.parse Invalid package.json: JSONParseError: Expected ',' or '}' after property value in JSON at position 45 (line 4 column 3) while parsing near "...version\": \"1.0.0\"\n  \"dependencies\": {\n  ..."
npm error JSON.parse Failed to parse JSON data.
npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T15_26_30_769Z-debug-0.log

When I ran npm install with npm 9.9.4, each line began with npm ERR!. The content was the same as with npm 10.9.9, except that there was one blank line before the last log line.

console
$ npx -y npm@9.9.4 install
npm ERR! code EJSONPARSE
npm ERR! path /path/to/my-app/package.json
npm ERR! JSON.parse Expected ',' or '}' after property value in JSON at position 45 (line 4 column 3) while parsing near "...version\": \"1.0.0\"\n  \"dependencies\": {\n  ..."
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/_logs/2026-11-12T15_26_31_665Z-debug-0.log

When there is a comment

Near the end of the message (one line before the log location), Note: package.json must be actual JSON, not just JavaScript. means that package.json must be real JSON, not JavaScript. The official package.json documentation also says at the top that the file must be JSON, not a JavaScript object literal.

A // comment, which is allowed in JavaScript, caused the same error in package.json.

console
$ cat -n package.json
     1	{
     2	  "name": "my-app",
     3	  "version": "1.0.0",
     4	  // A library for checking whether a value is a number
     5	  "dependencies": {
     6	    "is-number": "7.0.0"
     7	  }
     8	}
$ npm install
npm error code EJSONPARSE
npm error path /path/to/my-app/package.json
npm error JSON.parse Expected double-quoted property name in JSON at position 46 (line 4 column 3) while parsing near "...ersion\": \"1.0.0\",\n  // 数字かどうかを調べるライブラリ\n ..."
npm error JSON.parse Failed to parse JSON data.
npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T15_26_31_911Z-debug-0.log

In this case, the line in the message (line 4) was the comment line itself. Delete the comment line to fix it.

Finding the error location with node

The npm message is packed onto one line and uses \n for line breaks, so it can be hard to see where the problem is. When I read package.json with JSON.parse in Node.js, it showed the bad line as it is and marked the spot with ^. Below is the result from running it in the folder with the commented package.json.

console
$ node -e 'JSON.parse(require("fs").readFileSync("package.json", "utf8"))'
<anonymous_script>:4
  // A library for checking whether a value is a number
  ^

SyntaxError: Expected double-quoted property name in JSON at position 46 (line 4 column 3)
    at JSON.parse (<anonymous>)
(以下、Node.js の内部の行が続くので省略)

The same English text appears in npm's message because npm also reads package.json with JSON.parse internally. I checked the code in npm 10.9.9. @npmcli/package-json, which reads package.json, uses the json-parse-even-better-errors library to read JSON, and that library calls JSON.parse. The library is also what attaches the EJSONPARSE code when parsing fails.

Confirming that the fix removes the error

This is package.json after I fixed the comma and removed the comment. There is a comma between items, and there is no comma after the last item inside { }.

console
$ cat -n package.json
     1	{
     2	  "name": "my-app",
     3	  "version": "1.0.0",
     4	  "dependencies": {
     5	    "is-number": "7.0.0"
     6	  }
     7	}

I first read it with node, and it printed ok without an error.

console
$ node -e 'JSON.parse(require("fs").readFileSync("package.json", "utf8")); console.log("ok")'
ok

When I ran npm install in this state, EJSONPARSE did not appear and the package was installed (exit code 0). node_modules and package-lock.json were created too, and npm ls showed that is-number@7.0.0 was installed.

console
$ npm install

added 1 package, and audited 2 packages in 352ms

found 0 vulnerabilities
$ ls -A
node_modules
package-lock.json
package.json
$ npm ls
my-app@1.0.0 /path/to/my-app
`-- is-number@7.0.0

I omitted the blank line at the end of the npm ls output.

​Posted by 86