JSON5 Comments in package.json: What Each Tool Does

npm, pnpm and both Yarn generations reject a // comment in package.json. Bun accepts it, then deletes it on the next edit.

The usual workaround is a "//" key. It works at the top level and inside scripts, but it breaks npm install inside dependencies. We ran each package manager on 12-01-2026 and pasted the real errors below.

If you want real comments, pnpm can read package.json5, and the table at the end matches each need to the method that fits.

A package.json manifest with a handwritten note beside a dependency while package managers react to it

TL;DR: npm's docs say package.json "must be actual JSON, not just a JavaScript object literal", and npm 11.6.4 fails with EJSONPARSE on a // comment. Use a "//" key at the top level or in scripts, never in dependencies or devDependencies. For real comments use pnpm with package.json5 (see pnpm and JSON5) or keep the notes in a README.

Danger icon

What Happens When package.json Has a Comment

We put this file in an empty folder for each tool and ran its install command on 12-01-2026:

{ // the app "name": "demo-pkg", "version": "1.0.0" }
Tool Accepts the comment Real output
npm 11.6.4 No npm error code EJSONPARSE, then Invalid package.json: JSONParseError: Expected property name or '}' in JSON at position 4 (line 2 column 3) and Note: package.json must be actual JSON, not just JavaScript.
pnpm 12.25.1 No derive workspace root and package manager policy then key must be a string at line 2 column 3
Yarn 1.22.22 No error SyntaxError: ...package.json: Expected property name or '}' in JSON at position 4 (line 2 column 3)
Yarn 4.19.0 No Syntax Error: Expected property name or '}' in JSON at position 4 (line 2 column 3) naming the file
Bun 1.4.5 Yes bun install finished with no error on this file

The npm and both Yarn messages carry the same sentence as the Node.js JSON.parse error. The npm line "Expected property name or '}'" points at the first comment, so it reads like a broken key. Look for a comment or a trailing comma. The comments in JSON page shows the same error for any JSON file.

The pnpm message is shorter and does not name the file. We ran it through npx --yes pnpm@latest, which resolved to 12.25.1; Yarn 1 came from npx --yes yarn@latest, and Yarn 4 from npx --yes @yarnpkg/cli-dist@latest, because yarn@latest resolved to 1.22.22. Node.js was 24.22.1.

Bun accepting it is a trap. We added a dependency with bun add is-even to a commented file with an is-odd dependency already in it. Bun rewrote package.json and the // comment line was gone. If one teammate uses Bun and another uses npm, the file works for one of them, and the first Bun edit deletes the comment for everyone.

Comment icon

The "//" Key Convention

A "//" key is valid JSON, so every tool parses it. The note is a string (or an array of strings) stored under a key that no tool uses. It is a convention, not a feature: the npm package.json documentation does not mention it. Everything below is what we observed, not what is documented.

Top level

{ "//": "Top-level note", "name": "demo-pkg", "version": "1.0.0", "dependencies": { "is-odd": "3.0.1" } }

npm install reported "added 2 packages" with no warning. Then npm install is-even added the dependency and left the "//" key and its value in place, as did pnpm add is-even (12.25.1) and yarn add is-even (1.22.22). The top-level key is safe in all three.

Inside dependencies

"dependencies": { "//": "is-odd is pinned: 3.0.2 broke us", "is-odd": "3.0.1" }

This is the place people most want a note, and it fails. In dependencies the key is a package name, so the tools try to install a package called "//" at the version "is-odd is pinned...":

Tool Real output
npm 11.6.4npm error code EINVALIDPACKAGENAME and Invalid package name "//" of package "//@is-odd is pinned: 3.0.2 broke us": name can only contain URL-friendly characters. npm ls also fails with ELSPROBLEMS
pnpm 12.25.1ERR_PNPM_INVALID_DEPENDENCY_NAME: the project "contains a dependency with an invalid name: "//""
Bun 1.4.5error: invalid dependency name "//" and error: //@note failed to resolve

We did not test this case on Yarn. Treat it as unsafe there too. Put the reason for a pin in the top-level note or the README, and name the package in it: "//": "is-odd pinned to 3.0.1: 3.0.2 broke the build".

Repeated keys

JSON allows repeated keys in text, but a parser keeps one. We gave a file two top-level "//" keys, the first an array of two notes and the second a string, then ran npm pkg set description=hello. npm rewrote the file with one "//" key holding the last value, the string. The array was gone. The comments in JSON page shows the same last-one-wins result in plain Node.js. Use different key names ("//build", "//deps") or one array.

Terminal icon

Comments in Scripts and Custom Keys

In scripts a "//" key is a script that nobody runs. We tested this file:

"scripts": { "//": "Runs the build", "//test": "node test runner", "build": "echo building" }

npm install and npm run build worked. A plain npm run listed all three, the notes as entries named // and //test with the text underneath:

Scripts available in [email protected] via `npm run`: // Runs the build //test node test runner build echo building

That is a mild bonus: the note shows up where people look for commands. The cost is that tools which list scripts, such as editor script runners and CI dashboards, will show the notes as scripts too. We did not test those. A script key is a command name, so keep the note text out of anything you would not want a shell to run.

Some teams use a descriptive key instead of "//", such as "scripts-info" or "_notes". Any name works for the parser, so pick one convention per repository and keep it at the top level, away from dependencies. Fields that npm itself reads (description, keywords) are better than a note when the text is something a user should see.

Code file icon

package.json5 and package.yaml with pnpm

The pnpm docs say "In addition to the traditional package.json format, pnpm also supports package.json5" and package.yaml. That is the only mainstream route to real comments in a manifest. We tested it earlier and wrote it up: pnpm and package.json5 shows comments surviving pnpm add, the published tarball containing a plain package.json, and npm and Yarn failing on the file. Read it before you rename anything.

The short version: every developer and CI job in the repository must use pnpm, and nothing else may parse the manifest. Bots, scanners and editor integrations that look for package.json will not see a package.json5. Remember that package.json wins if both files exist.

Announcement icon

The Requests to npm, and Their Status

People have asked npm for comments in package.json for years. This is what each page showed on 12-01-2026; we describe status only as shown, and it can change.

Request Opened Status shown
npm/cli #793: allow JSONC or JSON5 for package.json 02-10-2020 Closed as completed on 06-02-2021 by an automated message saying npm v6 is no longer in active development and asking people to re-file against v7 or open an RFC. A comment as late as 12-31-2024 asks for it again
npm/rfcs #291: opt-in package.json5 that npm uses to regenerate package.json 11-21-2020 Open, with a linked pull request also open. Latest activity shown is 10-28-2026. We saw no npm decision on the page
npm/rfcs discussion #230: use JSON5 for package.json 09-16-2020 Marked unanswered; latest visible activity 02-02-2024. We saw no reply from an npm maintainer on the page

The objections in those threads are consistent. A contributor says in #230 that ".json means JSON. JSON5 would necessitate a different extension" and in #291 that adoption would be hard for tooling to handle. In #793 another commenter calls the change backwards incompatible because other tools would have to read the new syntax.

Evert Pot's post "JSON5" (01-09-2023) argues the other side and names the hard part: "Plus there's the whole chicken and egg thing with needing a JSON5 parser before we have dependencies." A package manager would need a JSON5 parser built in before it can install anything, including the parser. He says he would annotate a great deal in package.json if npm adopted it.

Target icon

Which Method for Which Need

Your need Method Watch out for
One note about the whole packageTop-level "//" key, or descriptionRepeated "//" keys keep only the last
Why a dependency is pinnedA top-level note that names the package, or a README sectionA "//" key inside dependencies breaks install in npm, pnpm and Bun
What a script does"//name" keys in scripts, or a docs pageNotes appear in npm run; do not make them commands
Real comments beside valuespackage.json5 with pnpmnpm and Yarn cannot read it; check bots and CI first
Real comments, mixed teamGenerate package.json from a commented source in your own buildTwo files to keep in sync; this is your own tooling, not an npm feature. Parse the source with the json5 package
Comments that must survive Bun editsDo not rely on // commentsBun 1.4.5 deleted ours on bun add
Notes for people reading the repoREADME, a docs/ file, or the pull requestThey can drift from the manifest, so link to them from the top-level note

More on writing notes that stay true is in comments best practices, and the full list of options for other file types is on comments in JSON.

Comments in package.json: Common Questions

Can package.json have comments?

Not // comments in npm, pnpm or Yarn, which failed in our test. Bun 1.4.5 accepted them. The npm docs say the file "must be actual JSON".

What does the "//" key do in npm?

Nothing. It is an ordinary key that npm ignores at the top level and in scripts, and that npm 11.6.4 keeps when it rewrites the file. Inside dependencies it fails.

Why does npm say "Expected property name or '}'"?

It is the JSON.parse message for a comment or other non-JSON token. In our file it pointed at position 4, the start of the comment.

Does pnpm allow comments?

In package.json5, yes; see our pnpm guide. In package.json, pnpm 12.25.1 failed on a // comment.

Will npm ever support JSON5 or JSONC?

We cannot say. The npm/rfcs request #291 was still open on 12-01-2026 with no decision shown on the page.

Is a comment in package.json published?

A "//" key sits in the file, so it ships with the package. We did not test what registry tooling does with it. Keep notes free of internal details.

Strip Comments From a File

Paste a commented manifest into the converter and copy back plain JSON.

Open the Converter