[英]Linux NodeJS global NPM package “:No such file or directory”
I am using Ubuntu 14.04 and have installed nodejs
and npm
with: 我正在使用Ubuntu 14.04并安装了
nodejs
和npm
:
sudo apt-get install nodejs npm
Then I made a symlink to enable packages to use the node
interpreter (instead of nodejs
): 然后我创建了一个符号链接,使包能够使用
node
解释器(而不是nodejs
):
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
I installed coffee-script
(for testing purposes) and my own package, mangarack
, with: 我安装了
coffee-script
(用于测试目的)和我自己的包, mangarack
,用:
sudo npm -g install coffee-script mangarack
When I run coffee
(part of coffee-script
), that package will run fine. 当我运行
coffee
( coffee-script
一部分)时,该包运行正常。 If I run mangarack
, I will get: 如果我运行
mangarack
,我会得到:
: No such file or directory.
I have the following in my package.json
: 我的
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
. 我看了一下
coffee-script
是如何做到的,看起来我的require
语句是绝对错误的,所以我用console.log
语句替换它,看看文件是否实际在node
运行。 It doesn't. 它没有。 What did I miss or miss-configure to enable Linux-based machines to run this package?
我错过或错过配置什么来启用基于Linux的计算机来运行此程序包?
Full source code references: 完整源代码参考:
The problem is the file bin/mangarack
uses carriage return, which causes error in linux environment. 问题是文件
bin/mangarack
使用回车,这会导致linux环境出错。 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
. 注意
node
后面的字符\\r
(十六进制模式下为0d
)。 you should remove it. 你应该删除它。
Solution: setup your project with $ git config core.autocrlf
then commit changes afterwards. 解决方案:使用
$ git config core.autocrlf
设置项目,然后提交更改。 see https://help.github.com/articles/dealing-with-line-endings/ 请参阅https://help.github.com/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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.