[BUG] Got "Permission Denied" when execute local CLI command by `npm link` after git commit in current branch
Nobody has claimed this yet.
- 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.
- In my project to build a CLI, I execute
npm linkto link my CLI to global, and it works; I usetest-cli createinstead. - Execute
test-cli creategot an inner execution issue, and it is because I forgot to use shebang, and I also added it, then it works. - Everything works fine, so I commit this change to git. Didn't execute
npm unlinkat this time. - After the commit, I retry to execute
test-cli create, but I have an issue in terminalzsh: permission denied: test-cli create, or eventest-cliitself. - I tried to execute
npm-unlinkandnpm-link, the issue still exists. - I tried to delete
test-cliin globalnode_modulesand retry 5, the issue still exists. - I tried to use
chmodor other syntax to add permission on the target file, or even usesudo, and I am pretty sure the target file has permission to execute, but the issue still exists. - I changed my branch from the current to the master (haven't merged yet), and everything works fine except the shebang issue.
- With 8, I re-checked my commit, there is nothing but only the line I add shebang.
- I also tried to clear the cache but still had the same issue.
- One thing is very strange, in this issue, when I change my codes and retry the
npm link, it always returns me anup to datelog with a during time. And when I trynpm unlink -g test-cli, it also returns me anup to datelog. The during time is almost the same around 700ms on this device. - 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
- Find a project, in my case a CLI.
- Execute
npm linkand check if it can work well by link. - Change some codes and commit them, especially the final file it executes.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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