0
sudo npm install  rd  -g  
+ rd@1.0.0
added 1 package in 2.097s


node
> var rd = require('rd');
Error: Cannot find module 'rd'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at repl:1:10
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:433:10)

请问,为什么?

debian8@debian:~$ sudo npm install  rd  -g  --save
+ rd@1.0.0
updated 1 package in 0.726s
debian8@debian:~$ node
> var rd = require('rd');
Error: Cannot find module 'rd'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25) 

没有用!

2个回答

0

加--save选项就行了。-g只是全局安装,并没有安装到项目里。加--save才会安装到项目里。

0

https://stackoverflow.com/que...

node shell 默认并不在全局找包

撰写答案