npm / npm/cli

[BUG] Got "Permission Denied" when execute local CLI command by `npm link` after git commit in current branch

Open
#6,906 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 10.x Release 9.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

It is a very weird issue. I am not sure if it is entirely related to npm, but it really brings a horrible experience.

  1. In my project to build a CLI, I execute npm link to link my CLI to global, and it works; I use test-cli create instead.
  2. Execute test-cli create got an inner execution issue, and it is because I forgot to use shebang, and I also added it, then it works.
  3. Everything works fine, so I commit this change to git. Didn't execute npm unlink at this time.
  4. After the commit, I retry to execute test-cli create, but I have an issue in terminal zsh: permission denied: test-cli create, or even test-cli itself.
  5. I tried to execute npm-unlink and npm-link, the issue still exists.
  6. I tried to delete test-cli in global node_modules and retry 5, the issue still exists.
  7. I tried to use chmod or other syntax to add permission on the target file, or even use sudo, and I am pretty sure the target file has permission to execute, but the issue still exists.
  8. I changed my branch from the current to the master (haven't merged yet), and everything works fine except the shebang issue.
  9. With 8, I re-checked my commit, there is nothing but only the line I add shebang.
  10. I also tried to clear the cache but still had the same issue.
  11. One thing is very strange, in this issue, when I change my codes and retry the npm link, it always returns me an up to date log with a during time. And when I try npm unlink -g test-cli, it also returns me an up to date log. The during time is almost the same around 700ms on this device.
  12. The target file (cli.js) can be executed directly by the node the whole time, and that's also a Plan B to keep on working.

So with the upper description, especially 11, I wonder if there are some issues between git, the file system, and npm? When I commit, git locks something but has a side effect on npm, so npm always thinks there is nothing changed and nothing to be done.

I think re-installing the node or deleting my local git repo can help, but I still wondering why. And the repo is for business so I cannot open it or provide any test files. Not sure if this issue only happens on my device.

Expected Behavior

No matter what we did to git, npm link can always link the current local module, or output some warnings or errors when there are issues in it.

Steps To Reproduce
  1. Find a project, in my case a CLI.
  2. Execute npm link and check if it can work well by link.
  3. Change some codes and commit them, especially the final file it executes.
  4. Retry 2.

Don't know if this can happen this issue.

Environment
  • npm: 10.2.0
  • Node.js: v18.18.1
  • OS Name: macOS Ventura 13.3
  • System Model Name: Macbook Pro
  • npm config:
; "user" config from /SecretPath/.npmrc

///SecretHost//:_auth = (protected) 
///SecretHost//:_authToken = (protected) 
; always-auth = true ; overridden by project
email = "notProvided@test.com" 
; registry = "http:///SecretHost/" ; overridden by project

; "project" config from /SecretPath/Documents/Workplace/test-cli/.npmrc

always-auth = true 
fsevents_binary_host_mirror = "https://npm.taobao.org/mirrors/fsevents/" 
puppeteer_download_host = "https://npm.taobao.org/mirrors/" 
registry = "http:///SecretHost/" 

; node bin location = /SecretPath/.nvm/versions/node/v18.18.1/bin/node
; node version = v18.18.1
; npm local prefix = /SecretPath/Documents/Workplace/test-cli
; npm version = 10.2.0
; cwd = /SecretPath/Documents/Workplace/test-cli
; HOME = /Users/Secret
; Run `npm config ls -l` to show all defaults.

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

Start by examining the npm link and npm unlink behavior around the linked package and its target cli.js. Reproduce the reported sequence with npm 10.2.0, Node.js v18.18.1, and macOS Ventura, comparing execution before and after the git commit; done means the current local module links and the CLI runs without permission errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, javascript, node.js
Domain
cli, developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.