2014-10-09 138 views
0

我試圖建立使用的NodeJS與下面的代碼LDAP客戶端:找不到模塊「ldapjs」

var ldap = require('ldapjs'); 
var client = ldap.createClient({ 
    url: 'ldap://10.11.4.130:389', 
}); 

但是當我嘗試運行,出現此錯誤:

module.js:340 
    throw err; 
    ^
Error: Cannot find module 'ldapjs' 
    at Function.Module._resolveFilename (module.js:338:15) 
    at Function.Module._load (module.js:280:25) 
    at Module.require (module.js:364:17) 
    at require (module.js:380:17) 
    at Object.<anonymous> (/home/elias/workspace/TestJS/app.js:64:12) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Function.Module.runMain (module.js:497:10) 

ldapjsnpm安裝了npm install ldapjs

[[email protected] ~]# npm ls 
/root 
├── [email protected] 
├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
[...] other modules 
└─┬ [email protected]   <----- 
    ├── [email protected] 
    ├── [email protected] 
    ├─┬ [email protected] 
    │ └── [email protected] 
    ├── [email protected] 
    ├─┬ [email protected] 
    │ └── [email protected] 
    └─┬ [email protected] 
    ├── [email protected] 
    └─┬ [email protected] 
     ├─┬ [email protected] 
     │ ├── [email protected] 
     │ ├── [email protected] 
     │ └── [email protected] 
     └─┬ [email protected] 
     └── [email protected] 
[[email protected] ~]# which node 
/bin/node 
[[email protected] ~]# which npm 
/bin/npm 
[[email protected] ~]# node -v 
v0.10.30 
[[email protected] ~]# npm -v 
1.3.6 

什麼是WR翁?

+0

你的腳本放在'/ root'中嗎? – mscdex 2014-10-09 21:24:35

+0

不,我以root身份安裝,但app.js位於'/ home/elias'中。 – elias 2014-10-09 21:26:01

回答

1

它看起來像你的腳本在/home/elias/workspace/TestJS,但你運行npm ls/root,所以它看起來像你安裝模塊到錯誤的地方。嘗試從/home/elias/workspace/TestJSnpm install ldapjs

模塊在本地安裝,通常位於當前工作目錄的子目錄下(除非cwd的任何父目錄中已經有node_modules)。

+0

像魅力一樣工作。非常感謝! – elias 2014-10-09 21:30:14

0

npm install ldapjs會起作用。另外,如果您使用的是git,並且npm install ldapjs最初不起作用,請嘗試使用git clean -fdx刪除所有已安裝的軟件包,然後執行npm install(如果ldapjs未添加到您的package.json中),則npm install ldapjs