Skip to content

[BUG] executable permissions aren't set if a .bin symlink already exists #4149

Open
@bglw

Description

@bglw

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

If a folder within node_modules is deleted and npm install is run, npm will not mark any bin files as executable if the symlink to that file still exists in node_modules/.bin

This means that if node_modules was only partially cleaned up, the re-install can land in a broken state. We're seeing this happen on CI environments with quirks in the caching / preserving of node_module folders.

Expected Behavior

A re-install should also re-update all bin files to have executable permissions.

Steps To Reproduce

  1. Using Node v16.13.1 (npm v8.1.2) on macOS or Ubuntu
  2. With the package.json
{
  "name": "symlink-test",
  "private": true,
  "scripts": {
    "start": "webpack"
  },
  "dependencies": {
    "webpack": "^5.65.0"
  }
}
  1. Run npm install
  2. Run npm start and you will see CLI for webpack must be installed. (indicating that the webpack command successfully executed)
  3. Run ls -l node_modules/webpack/bin/webpack.js and see the permissions -rwxr-xr-x
  4. Run rm -rf ./node_modules/webpack/
  5. Run npm install
  6. Run npm start and you will see sh: path/to/node_modules/.bin/webpack: Permission denied
  7. Run ls -l node_modules/webpack/bin/webpack.js and see the permissions -rw-r--r--

Previous NPM versions

Following the above steps in npm 6 or npm 7 will not throw the error, and using ls -l node_modules/webpack/bin/webpack.js will always show the permissions -rwxr-xr-x, even on this partial install state.

Environment

  • npm: v8.1.2
  • Node: v16.13.1
  • OS: macOS 11.6
  • platform: Macbook Pro
  • npm config:
; "user" config from /Users/liambigelow/.npmrc

//npm.pkg.github.com/:_authToken = (protected) 
//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /Users/liambigelow/.nvm/versions/node/v16.13.1/bin/node
; cwd = /Users/liambigelow/tmp/symtest3
; HOME = /Users/liambigelow
; Run `npm config ls -l` to show all defaults.

NOTE: This behavior was initially observed on Ubuntu images running inside Docker. I am reproducing it on a Macbook Pro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions