1

I have NPM package with a bin property linking to a script, e.g.

/foo/package.json

{
    "name": "foo",
    "bin": "./dist/index.js"
}

/foo/src/index.js

#! /usr/bin/env node

console.log('Hello, World!');

I use npm link to create a globally-installed symbolic link of foo package.

Then I use:

node ./node_modules/.bin/babel\
    --watch ./src\
    --out-dir ./dist

Next, I have a bar package.

package.json

{
    "name": "bar",
    "scripts": {
        "test-foo": "foo"
    }
}

I use npm link foo to create a symlink from the local node_modules folder to the global symlink.

Then I attempt to execute npm run test-foo. I expect to get "Hello, World!" message. Instead, I get the following error message:

npm run test-foo

> bar@0.0.0 test-foo /bar
> foo

sh: /Users/gajus/bar/node_modules/.bin/foo: Permission denied

npm ERR! Darwin 15.2.0
npm ERR! argv "/Users/gajus/.nvm/versions/node/v5.3.0/bin/node" "/Users/gajus/.nvm/versions/node/v5.3.0/bin/npm" "run" "test-foo"
npm ERR! node v5.3.0
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! bar@3.7.3 test-foo: `foo`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the table@3.7.3 test-foo script 'foo'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the table package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     foo
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs table
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls table
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/gajus/Documents/dev/gajus/table/npm-debug.log

Which is basically complaining that current user does not have permission to execute /Users/gajus/bar/node_modules/.bin/foo file.

I can solve this with:

chmod +x /Users/gajus/bar/node_modules/.bin/foo

However, I do not understand what is the reason that this file does not have permission to be executed in the first place. I am running babel program as the same user.

It appears to be an issue with the way NPM setups a global symlink (it sets it once. When babel --watch creates a new file, it no longer persists).

What is the solution to have +x persist with npm link?

Gajus
  • 69,002
  • 70
  • 275
  • 438

1 Answers1

4

The solution was pretty simple: give permissions to execute the source file, i.e.,

chmod +x /foo/src/index.js

When Babel program copies the files, it will also copy the permissions of that file. This works with --watch too.

Gajus
  • 69,002
  • 70
  • 275
  • 438