Skip to content

[BUG] npm install fails with EACCES on a package.json with no EOF #3234

Closed
@mnmkng

Description

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

NPM 7 fails with an EACCES error when npm install is run with a package.json that:

  1. does not have a new line at the end, AND
  2. the user does not have the permission to write to the package.json.

It most likely happens because of npm/npm#18545

NPM 6 does not fail like this.

Expected Behavior

I would expect npm install to work even with only read permissions to package.json.

The EOF new line has no meaning there, everything should work fine without it (on most systems), NPM does not really need to write to the package.json so read rights should be enough to execute npm install.

NPM 6 most likely does not fail, because it runs with higher privileges and writes the EOF even if the permissions on the package.json prevent it, but that's a different issue.

Steps To Reproduce

  1. npm init -y
  2. remove EOF new line from package.json
  3. chmod 444 package.json
  4. npm i
  5. NPM 7 fails with EACCES, NPM 6 keeps going

Environment

  • OS: MacOs, various Linuxes
  • Node: 15, 16
  • npm: 7

Metadata

Assignees

Labels

Bugthing that needs fixingPriority 2secondary priority issueRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions