0

I have a package.json at:

/home/user/dev/project/package.json

If I navigate to this location:

cd /home/user/dev/project

Then run a command:

npm run compile

It works and there are no errors.

However, if I try to run the command like this

/home/user/dev/project/ npm run compile

I get a message:

zsh: permission denied: /home/user/dev/project/

Why is this happening? I have not changed the user I'm logged in as.

sander
  • 1,426
  • 4
  • 19
  • 46
  • 1
    Because `/home/user...` is a folder, and you try to execute a folder, and that's not possible. See https://stackoverflow.com/questions/36172442/how-can-i-get-npm-start-at-a-different-directory on how to do this correctly. – Robert May 16 '22 at 17:10
  • In the second case, you are trying to run a program named `/home/user/dev/project` with the arguments `npm`, `run` and `compile`. This does not make sense. Note that the first word of a statement is the program to be executed, and the following words are the arguments of that programm. – user1934428 May 18 '22 at 07:46

1 Answers1

1

The first word of a command is the name of the program to run. The directory is not an executable program, so you get that error.

If you want to refer to a file in another directory, put the directory name in the filename:

npm run compile /home/user/dev/project
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you! But a minor correction, in my case the command would be: npm run compile /home/user/dev/project Because the compile is refering to a script inside of package.json. – sander May 16 '22 at 17:12
  • 1
    Sorry, I was confused and thought `compile` was the filename to run. – Barmar May 16 '22 at 17:14
  • Another thing, if I run the command as `npm run compile /home/user/dev/project`it does work but I have an error with compilation itself: `Could not resolve the path '/home/user/dev/project' with the extension '.ts', 'tsx'...` I don't know why this happens, but if I run the command as: `npm run compile --prefix /home/user/dev/project` It does not give the error. So I would use that one instead. – sander May 16 '22 at 17:27
  • This seems to be more about how to use `npm` properly. – Barmar May 16 '22 at 17:27