Skip to content

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

@LikeDreamwalker

Description

@LikeDreamwalker

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 = "[email protected]" 
; 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions