I wrote a module which I published to npm a moment ago (https://npmjs.org/package/wisp)
So it installs fine from the command line:
$ npm i -g wisp
However, when I run it from the command line, I keep getting an error that optimist isn't installed:
$ 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)
However, I have specified in package.json as a dependancy:
{ "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" } }
Does anyone know what to do to get this running? I know its to do with the bin part adding the executable to bin and the node_modules in that directory being empty. No idea how to resolve this.
To install a module from npm globally, you'll simply need to use the --global flag when running the install command to have the module install globally, rather than locally (to the current directory). Note: One caveat with global modules is that, by default, npm will install them to a system directory, not a local one.
Path of Global Packages in the system: Global modules are installed in the standard system in root location in system directory /usr/local/lib/node_modules project directory. Command to print the location on your system where all the global modules are installed.
To check for all globally installed packages and its dependencies, run the npm list command followed by the -g flag. This above command prints the all globally installed packages in tree view. You can also check if a specific package is installed globally or not using the npm list -g followed by package name.
For anyone else running into this, I had this problem due to my npm
installing into a location that's not on my NODE_PATH
.
[root@uberneek ~]# which npm /opt/bin/npm [root@uberneek ~]# which node /opt/bin/node [root@uberneek ~]# echo $NODE_PATH
My NODE_PATH was empty, and running npm install --global --verbose promised-io
showed that it was installing into /opt/lib/node_modules/promised-io
:
[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]
My script fails on require('promised-io/promise')
:
[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)
I probably installed node and npm from source using configure --prefix=/opt
. I've no idea why this has made them incapable of finding installed modules. The fix for now is to point NODE_PATH at the right directory:
export NODE_PATH=/opt/lib/node_modules
My require('promised-io/promise')
now succeeds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With