Persistent “Cannot find module” errors when instal

2019-09-11 02:36发布

I started with a blank install of Lion, installed Xcode 4.1, then followed the instructions at http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac to install rvm, sqlite3, rails and then installed node v0.2.5 and redis v2.0.4. I then tried to install juggernaut:

git clone git://github.com/maccman/juggernaut.git --recursive
cd juggernaut
sudo node server.js

After sudo node server.js I get the following error. I have somehow managed to get the same error on 2 separate computers, one with SL 10.6.6 and the other with Lion, clearly I am missing a step somewhere. Also 'optimist' is not the only module that is not found, many other variations of this error e.g cannot find module 'graceful-fs' etc. I have tried installing the modules manually. Please help with this problem.

fred:juggernaut fred$ sudo node server.js

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: Cannot find module 'optimist'
    at Function._resolveFilename (module.js:317:11)
    at Function._load (module.js:262:25)
    at require (module.js:346:19)
    at Object.<anonymous> (/Users/fred/Desktop/redis-2.0.4/juggernaut/server.js:2:12)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at Array.<anonymous> (module.js:421:10)
    at EventEmitter._tickCallback (node.js:126:26)
fred:juggernaut fred$ 

2条回答
一夜七次
2楼-- · 2019-09-11 02:51

I may have had the same issue, or at least related. (Check out this SO question)

Your problem could be in your .bashrc or your .profile.

What does echo $PATH output? Depending on where your your node directory is located, it should output export PATH=$HOME/​local/node/bin:$PATH.

查看更多
来,给爷笑一个
3楼-- · 2019-09-11 03:06

I had the same problem under ubuntu 12.10 when I tried to run "nodejs server.js" after cloning the juggernaut git repo.

Eventually I installed juggernaut with npm ("npm install -g juggernaut") and now I can successfully run "nodejs /usr/local/lib/node_modules/juggernaut/server.js" (path may depend on your npm module installation).

查看更多
登录 后发表回答