zsh: permission denied: after npm link
Asked Answered
E

2

5

I am trying to run basic CLI command, but after npm link getting:

zsh: permission denied: testcom

File myfile contains:

#!/usr/local/bin/ node


console.log('Hello!')

Running ls -alh:

-rwxr-xr-x  1 markhorton  staff    46B  4 Dec 20:37 myfile

package.json:

{
  "name": "katya",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "bin": {
    "testcom": "myfile"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

However, running testcom says permission is denied.

Would be vey grateful for any help or suggestions. Thank you very much, Katya

Exorbitant answered 4/12, 2019 at 12:46 Comment(3)
There's a stray space in your shebang; it should be #!/usr/local/bin/node. You're getting an error in trying to execute the directory /usr/local/bin.Pratt
myfile also has to have execute permission set.Pratt
@Pratt thank you so much, it works now!Exorbitant
K
4

If your permissions get missed up, you can unlink and relink to fix the problem. (I have even had npm permissions get messed up after an OS update.)

npm unlink -g
npm link
Knowledge answered 31/8, 2023 at 16:10 Comment(0)
V
2

As @chepner said, the JavaScript file you are trying to run must have execute permissions on it.

$ chmod +x myfile
Villegas answered 18/1, 2023 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.