node.js 全局安装的 npm-packages 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15843199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:08:09  来源:igfitidea点击:

globally installed npm-packages not working

node.jsubuntucoffeescriptnpm

提问by tibtob

local npm-packages work as predicted, but it seems impossible for me to get globally-installed packages running. It doesn't even throw any error, it's just not doing anything ( express, coffee, etc.. )

本地 npm 包按预期工作,但我似乎不可能运行全局安装的包。它甚至没有抛出任何错误,它只是没有做任何事情(快递、咖啡等。)

This was not bothering me much until I wanted to use coffee-script.

在我想使用咖啡脚本之前,这并没有困扰我。

things I allready checked ( I'm on Xubuntu 12.04 ):

我已经检查过的东西(我在 Xubuntu 12.04):

  • npm lists it
  • its installed in /usr/local/bin
  • ( updated | uninstalled | reinstalled ) npm via ( npm | apt-get )
  • uninstalled nodejs and did fresh git-rebuild to /opt/bin/node

    => same thing..

  • npm 列出它
  • 它安装在 /usr/local/bin
  • (更新 | 卸载 | 重新安装) npm 通过( npm | apt-get )
  • 卸载 nodejs 并对 /opt/bin/node 进行了新的 git-rebuild

    => 同样的事情..

anyone knows a solution?

有人知道解决方案吗?

采纳答案by tibtob

turns out it tried to start with nodeinstead of nodejscommand. So in /usr/local/lib/node_modules/coffee-script/bin/coffeeI changed #!/usr/bin/env nodeto #!/usr/bin/env nodejsand works fine now.

原来它试图开始node而不是nodejs命令。所以/usr/local/lib/node_modules/coffee-script/bin/coffee我改变了#!/usr/bin/env node#!/usr/bin/env nodejs现在工作得很好。

回答by user568109

is NODE_PATHvariable set on your environment

NODE_PATH在您的环境中设置的变量

//show if set
echo $NODE_PATH

//set NODE_PATH
NODE_PATH="/usr/local/lib/node_modules"

The NODE_PATHshould contain the location of directories where the modules are installed. It can have multiple directories (colon seperated).

NODE_PATH应包含在模块安装目录的位置。它可以有多个目录(冒号分隔)。