NPM global install
NPM global install "cannot find module"
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. (/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)
However, I have specified in package.json as a dependancy:
{ "name": "wisp", "author": "Brendan Scarvell ", "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.
Answer by Neek for NPM global install "cannot find module"
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 npm@1.1.45 npm info using node@v0.8.4 [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.
Answer by randomness for NPM global install "cannot find module"
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)
Answer by Cando Zhou for NPM global install "cannot find module"
add this to beginning of prog(mac):
module.paths.push('/usr/local/lib/node_modules');
Answer by user2921139 for NPM global install "cannot find module"
I got the "optimist" module error and I just did "npm install" to resolve it. went past that error.
https://github.com/mbloch/mapshaper/issues/12
Answer by Dmitriy for NPM global install "cannot find module"
Had the same problem on one of the test servers running Ubuntu
under root
. Then created a new user using useradd -m myuser
and installed everything (nvm
, node
, packages) as myuser
. Now it's working fine.
Answer by Will for NPM global install "cannot find module"
For some (like me) that nothing else worked, try this:
brew cleanup brew link node brew uninstall node brew install node
Hope it helps someone :)
Answer by Dmitry for NPM global install "cannot find module"
On windows if you just did a clean install and you get this you need blow away your npm cache in \AppData\Roaming
Answer by P M for NPM global install "cannot find module"
For Windows, from Nodejs cannot find installed module on Windows? what worked for me is running npm link as in
npm link wisp
Answer by GT. for NPM global install "cannot find module"
In my case both node
and npm
were in same path (/usr/bin
). The NODE_PATH
was empty, so the npm
placed the global modules into /usr/lib/node_modules
where require(...)
successfully find them. The only exception was the npm
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 empty NODE_PATH
and node started from /usr/bin
. So I had two options:
- link
/usr/lib64/node_modules/npm
to/usr/lib/node_modules/npm
- move modules from
/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.
Answer by user1959076 for NPM global install "cannot find module"
$ vim /etc/profile.d/nodejs.sh
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript export NODE_PATH="$NODE_PATH"
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment