我正在尝试使用带有以下代码的NodeJS构建LDAP客户端:
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)
ldapjs
是通过npm
和npm install ldapjs
安装的[root@localhost ~]# 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]
[root@localhost ~]# which node
/bin/node
[root@localhost ~]# which npm
/bin/npm
[root@localhost ~]# node -v
v0.10.30
[root@localhost ~]# npm -v
1.3.6
怎么了?
最佳答案
看起来您的脚本在/home/elias/workspace/TestJS
中,但是您正在从npm ls
运行/root
,因此看起来您将模块安装在错误的位置。尝试从npm install ldapjs
执行/home/elias/workspace/TestJS
。
模块是本地安装的,通常在当前工作目录的子目录下(除非cwd的任何父目录中已经有node_modules
)。