26

I've created a node-module that has a build script that gets called after the installation. The build script clones a git repository and copies some files of it to another folder. The problem: on npm install, the script does not get sufficient permissions and I get the following error:

sh: ./build.js: Permission denied

How can I give the build script sufficient permissions to do its job?

I want that the users just can do npm install mymodule and the build-script then does its job on any system.

Any ideas?

Van Coding
  • 24,244
  • 24
  • 88
  • 132

1 Answers1

58

Do you have the x flag on build.js?

chmod +x build.js

And the first line of your script should tell how to execute the script from the shell:

#!/usr/bin/env node
Pascal Belloncle
  • 11,184
  • 3
  • 56
  • 56
  • 3
    Aaah! From the npm documentation, I thought that scripts with the ending ".js" automatically get executed by node. But since they also just get called as script and thus need the permission to get executed, this is obvious. Thanks. Instead of the 2 additions you mentioned, I also could simply write "install":"node build" in the package.json. – Van Coding Feb 28 '13 at 09:49
  • if the build is in dist/build.js. run dist/build instead. – Ben Cheng Oct 13 '20 at 16:05