最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Linux NodeJS global NPM package ":No such file or directory" - Stack Overflow

programmeradmin0浏览0评论

I am using Ubuntu 14.04 and have installed nodejs and npm with:

sudo apt-get install nodejs npm

Then I made a symlink to enable packages to use the node interpreter (instead of nodejs):

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

I installed coffee-script (for testing purposes) and my own package, mangarack, with:

sudo npm -g install coffee-script mangarack

When I run coffee (part of coffee-script), that package will run fine. If I run mangarack, I will get:

: No such file or directory.

I have the following in my package.json:

"bin": {
  "mangarack": "./bin/mangarack"
},

And that file contains:

#!/usr/bin/env node

require('../lib/cli/index');

I looked at how coffee-script did it and it seems like my require statement is absolutely wrong, so I replaced that with a console.log statement to see if the file would actually run in node. It doesn't. What did I miss or miss-configure to enable Linux-based machines to run this package?

Full source code references:

  • npm:
  • git: .js

I am using Ubuntu 14.04 and have installed nodejs and npm with:

sudo apt-get install nodejs npm

Then I made a symlink to enable packages to use the node interpreter (instead of nodejs):

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

I installed coffee-script (for testing purposes) and my own package, mangarack, with:

sudo npm -g install coffee-script mangarack

When I run coffee (part of coffee-script), that package will run fine. If I run mangarack, I will get:

: No such file or directory.

I have the following in my package.json:

"bin": {
  "mangarack": "./bin/mangarack"
},

And that file contains:

#!/usr/bin/env node

require('../lib/cli/index');

I looked at how coffee-script did it and it seems like my require statement is absolutely wrong, so I replaced that with a console.log statement to see if the file would actually run in node. It doesn't. What did I miss or miss-configure to enable Linux-based machines to run this package?

Full source code references:

  • npm: https://www.npmjs/package/mangarack
  • git: https://github./Deathspike/mangarack.js
Share Improve this question asked Dec 6, 2014 at 12:37 DeathspikeDeathspike 8,8006 gold badges46 silver badges83 bronze badges 2
  • 1 If your editor inserts carriage returns, well, you should really switch to a real one. Or find where to change the behaviour. – Stefano Sanfilippo Commented Dec 6, 2014 at 14:16
  • Indeed, I apparently should switch to a real one. :-) – Deathspike Commented Dec 6, 2014 at 17:42
Add a ment  | 

1 Answer 1

Reset to default 11

The problem is the file bin/mangarack uses carriage return, which causes error in linux environment. see what I got:

$ mangarack --help
env: node\r: No such file or directory

$ head -n 1 `which mangarack` | hexdump
0000000 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 6e
0000010 6f 64 65 0d 0a
0000015

Notice the character \r(0d in hex mode) after node. you should remove it.

Solution: setup your project with $ git config core.autocrlf then mit changes afterwards. see https://help.github./articles/dealing-with-line-endings/

the expected result after fix should be:

$ head -n 1 `which mangarack` | hexdump
0000000 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 6e
0000010 6f 64 65 0a
0000015
发布评论

评论列表(0)

  1. 暂无评论