Skip to content

Support comments in package.json #8751

@Timmmm

Description

@Timmmm

Sorry if there's an existing issue for this but I only found #793 which is closed. I believe this is the status quo:

  1. Users really want this. Look at this StackOverflow question - over 600 upvotes!
  2. None of the current workarounds are very good.
  3. It would be a (minor) breaking change.

The current workarounds are:

  1. You can officially add a single top-level key "//". This sucks because I want more than one comment!
  2. Various hacks to put comments inside script commands. This sucks because it only works for scripts, and it's also terrible.
  3. Use duplicate keys. This sucks because JSON's duplicate key handling is not well defined, and NPM will delete the duplicate keys if it modifies package.json.
  4. Generate package.json from another file. This is probably the best solution right now but it means you can't npm install -D stuff and it's an extra step.

These all really suck. This is an age-old feature request wanted by many many people.

As far as I understand it the reason NPM "can't" be changed to just support package.json5 or package.jsonc is that third party tools would get confused when they try to read package.json and it's not there. I can think of two solutions:

  1. When you run npm, as well as generating package-lock.json it also generates package.json (and this should be .gitignored if you also have package.json{5,c}). Are there any third party tools that want to modify package.json?
  2. Just ask those third party tools to support package.json{5,c} too. This is clearly a smaller problem than not allowing comments in NPM's most important config file forever.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions