NPM global install “cannot find module”
我写了一个模块,我刚刚发布到npm(https://npmjs.org/package/wisp)
所以它从命令行安装很好:
但是,当我从命令行运行它时,我一直收到一个错误,即没有安装optimist:
1 2 3 4 5 6 7 8 9 10 11 12 | $ wisp Error: Cannot find module 'optimist' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) at Object. (/usr/local/lib/node_modules/wisp/wisp:12:10) at Object. (/usr/local/lib/node_modules/wisp/wisp:96:4) at Module._compile (module.js:449:26) at Object.exports.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:68:25) at compileScript (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:135:29) at fs.stat.notSources.(anonymous function) (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:110:18) |
但是,我在package.json中指定为依赖:
1 2 3 4 5 6 7 8 9 10 11 12 13 | { "name":"wisp", "author":"Brendan Scarvell <[email protected]>", "version":"0.1.0", "description":"Global nodejs file server", "dependencies": { "optimist":"~0.3.4" }, "repository":"git://github.com/tehlulz/wisp", "bin": { "wisp" :"./wisp" } } |
有谁知道怎么做才能让这个运行? 我知道它与bin部分有关,将可执行文件添加到bin并且该目录中的node_modules为空。 不知道如何解决这个问题。
对于遇到此问题的其他人,由于我的
1 2 3 4 5 | [root@uberneek ~]# which npm /opt/bin/npm [root@uberneek ~]# which node /opt/bin/node [root@uberneek ~]# echo $NODE_PATH |
我的NODE_PATH是空的,运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@uberneek ~]# npm install --global --verbose promised-io npm info it worked if it ends with ok npm verb cli [ '/opt/bin/node', npm verb cli '/opt/bin/npm', npm verb cli 'install', npm verb cli '--global', npm verb cli '--verbose', npm verb cli 'promised-io' ] npm info using [email protected] npm info using [email protected] [cut] npm info build /opt/lib/node_modules/promised-io npm verb from cache /opt/lib/node_modules/promised-io/package.json npm verb linkStuff [ true, '/opt/lib/node_modules', true, '/opt/lib/node_modules' ] [cut] |
我的脚本在
1 2 3 4 5 6 7 | [neek@uberneek project]$ node buildscripts/stringsmerge.js module.js:340 throw err; ^ Error: Cannot find module 'promised-io/promise' at Function.Module._resolveFilename (module.js:338:15) |
我可能使用
1 | export NODE_PATH=/opt/lib/node_modules |
我的
将此添加到prog(mac)的开头:
默认情况下,节点不会在/ usr / local / lib / node_module中查看加载全局模块。
请参阅http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders中解释的模块加载
所以要么你必须
1)将/ usr / local / lib / node_module添加到NODE_PATH并导出它
要么
2)将已安装的节点模块复制到/ usr / local / lib / node。
(正如加载模块节点的链接中所解释的那样,将在此路径中搜索并将起作用)
对于一些人(像我一样)没有其他工作,试试这个:
1 2 3 4 | brew cleanup brew link node brew uninstall node brew install node |
希望它可以帮助别人:)
我得到了"乐观主义"模块错误,我只是做了"npm install"来解决它。过了那个错误。
https://github.com/mbloch/mapshaper/issues/12
我有
1 | npm install request-promise --global |
同
1 | npm install request-promise --cli |
工作(来源)
另外,尝试设置环境变量
1 2 3 | NODE_PATH=%AppData% pm ode_modules |
$ vim /etc/profile.d/nodejs.sh
1 2 | NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript export NODE_PATH="$NODE_PATH" |
在
在Windows上,如果你刚刚进行了全新安装而你得到了这个,你需要在 AppData roaming中吹掉你的npm缓存
在我的情况下,
唯一的例外是
-
将
/usr/lib64/node_modules/npm 链接到/usr/lib/node_modules/npm -
将模块从
/usr/lib/node_modules/* 移动到/usr/lib64/node_modules/ 并设置NODE_PATH=/usr/lib64/node_modules
两者都有效。我正在使用OpenSUSE 42.1和更新存储库中的nodejs包。版本是4.4.5。
我这样做的方式很简单......
更新Web驱动程序管理器
对我来说很好。
希望这可以帮助你......
我收到此错误
对于Windows,正如其他答案所示,您需要一个干净的Node安装:
- 卸载Node.js.
-
删除
C:\Users\user\AppData 中的两个文件夹
oamingnpm 和npm_cache - 重新启动Windows并安装Node.js.
-
运行
npm init 或(默认配置为npm init --yes ) -
为
NODE_PATH 设置Windows环境变量。此路径是安装软件包的位置。它可能类似于NODE_PATH = C:\Users\user
ode_modules or C:\Users\user\AppData
oaming
pm
ode_modules -
启动一个新的cmd控制台,
npm 应该可以正常工作
注意 :
在重新安装Node.js之前尝试最后几点,它可以节省您一些时间并避免重新安装所有软件包。
对于Mac用户,最好使用手动安装:
To minimize the chance of permissions errors, you can configure npm to
use a different directory. In this example, it will be a hidden
directory on your home folder.Back-up your computer before you start.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g.
if you don't want to modify ~/.profile):
1 NPM_CONFIG_PREFIX=~/.npm-global
参考:https://docs.npmjs.com/getting-started/fixing-npm-permissions
对于Windows,从Nodejs无法在Windows上找到已安装的模块?对我有用的是运行npm链接,如
1 | npm link wisp |
我刚刚遇到了
然后我尝试了这个:运行
它有效。
我有与OP相同的错误,但是我可以看到日志
事实证明,/ usr / bin / node程序(符号链接)不再与
在debian上安装它的正确方法是
我不得不将C: Users {Username} AppData roaming npm添加到我的env变量中然后我可以安装东西。