eisbehr
eisbehr

Reputation: 12452

Can't link command to node script file, no such file or directory

I've got trouble when trying to link a commant to a javascript file with npm on a linux machine. Just assume some simple script and package.json:

package.json

"bin": {
  "test": "./test.js"
},

test.js

#!/usr/bin/env node
console.log("test");

installation

$ sudo npm install
$ sudo npm link

Doing this on a windows machine causes no problems. Everything works fine. But on a linux / Raspbian system it keeps telling me:

: no such file or directory

I have already linked the binaries of node with:

$ sudo ln -s /usr/bin/nodejs /usr/bin/node

And to be sure, I've updated to the latest version of node, 7.10.0. But nothing helps. The message still appears. I have no idea whats wrong ...

Upvotes: 0

Views: 563

Answers (1)

eisbehr
eisbehr

Reputation: 12452

After a long search, the problem seems to be the windows line endings. They needed to be converted to unix style endings. This was the only change I've made, and now it works. This problem belongs only to the shebang line, because the node interpreter itself has no problem with the original file ...

For this test I installed and used dos2unix, which convert files:

$ sudo apt install dos2unix
$ sudo dos2unix test.js

After doing this, the initial test command works like a charm. So I've change the file on the development version to unix style, so I don't need to run this anymore.

Upvotes: 1

Related Questions