npm / npm/cli

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

Open
#4,149 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the package.json shown, npm install, removal of node_modules/webpack, and npm start. Trace the install path responsible for bin files and verify that a reinstall restores executable permissions for node_modules/webpack/bin/webpack.js and allows npm start to run without Permission denied.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.