NPM全局安装“找不到模块”

我写了一个模块,我刚才将其发布到npm(https://npmjs.org/package/wisp)


因此,可以从命令行安装正常:


$ npm i -g wisp


但是,当我从命令行运行它时,我不断收到未安装乐观主义者的错误:


$ 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.<anonymous> (/usr/local/lib/node_modules/wisp/wisp:12:10)

    at Object.<anonymous> (/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中指定了依赖性:


{

  "name": "wisp",

  "author": "Brendan Scarvell <bscarvell@gmail.com>",

  "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为空。不知道如何解决这个问题。


尚方宝剑之说
浏览 2438回答 3
3回答

Qyouu

对于遇到此问题的其他任何人,由于我npm将其安装到不在我的位置上而遇到了这个问题NODE_PATH。[root@uberneek ~]# which npm/opt/bin/npm[root@uberneek ~]# which node/opt/bin/node[root@uberneek ~]# echo $NODE_PATH我的NODE_PATH为空,运行npm install --global --verbose promised-io显示它正在安装到中/opt/lib/node_modules/promised-io:[root@uberneek ~]# npm install --global --verbose promised-ionpm info it worked if it ends with oknpm verb cli [ '/opt/bin/node',npm verb cli&nbsp; &nbsp;'/opt/bin/npm',npm verb cli&nbsp; &nbsp;'install',npm verb cli&nbsp; &nbsp;'--global',npm verb cli&nbsp; &nbsp;'--verbose',npm verb cli&nbsp; &nbsp;'promised-io' ]npm info using npm@1.1.45npm info using node@v0.8.4[cut]npm info build /opt/lib/node_modules/promised-ionpm verb from cache /opt/lib/node_modules/promised-io/package.jsonnpm verb linkStuff [ true, '/opt/lib/node_modules', true, '/opt/lib/node_modules' ][cut]我的脚本失败require('promised-io/promise'):[neek@uberneek project]$ node buildscripts/stringsmerge.js&nbsp;module.js:340&nbsp; &nbsp; throw err;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^Error: Cannot find module 'promised-io/promise'&nbsp; &nbsp; at Function.Module._resolveFilename (module.js:338:15)我可能使用的源安装了node和npm configure --prefix=/opt。我不知道为什么这使他们无法找到已安装的模块。现在的解决方法是将NODE_PATH指向正确的目录:export NODE_PATH=/opt/lib/node_modules我require('promised-io/promise')现在成功了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Node.js