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 <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"
}
}
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.
$ vim /etc/profile.d/nodejs.sh
In my case both
node
andnpm
were in same path (/usr/bin
). TheNODE_PATH
was empty, so thenpm
placed the global modules into/usr/lib/node_modules
whererequire(...)
successfully find them. The only exception was thenpm
module, which came with the nodejs package. Since I'm using 64 bit system, it was placed into/usr/lib64/node_modules
. This is not where require(...) searches in case of emptyNODE_PATH
and node started from/usr/bin
. So I had two options:/usr/lib64/node_modules/npm
to/usr/lib/node_modules/npm
/usr/lib/node_modules/*
to/usr/lib64/node_modules/
and setNODE_PATH=/usr/lib64/node_modules
Both worked. I'm using OpenSUSE 42.1 and the nodejs package from updates repository. Version is 4.4.5.
By default node does not look inside the /usr/local/lib/node_module for loading global modules. Refer the module loading explained in http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
So either you have to 1)add the /usr/local/lib/node_module to NODE_PATH and export it or 2)copy the installed node modules to /usr/local/lib/node . (As explained in the link for loading module node will search in this path and will work)
For some (like me) that nothing else worked, try this:
Hope it helps someone :)
For Mac User's It's Best use the manual installation:
Reference : https://docs.npmjs.com/getting-started/fixing-npm-permissions
On windows if you just did a clean install and you get this you need blow away your npm cache in \AppData\Roaming