我有一个像这样的目录结构:
project
lib
paperboy
redis-client
node-cookie
srv
main.js
...
我从项目目录启动 main.js:
$ node srv/main.js
在 main.js 中,我可以这样做:
paperboy = require('./lib/paperboy');
但是,这失败了:
redis = require('./lib/redis-client');
同样,如果我在“项目”目录中启动交互式节点,我可以要求 paperboy,但不能要求 redis-client。我得到的错误是:
> require('./lib/redis-client')
Error: Cannot find module './lib/redis-client'
at resolveModuleFilename (node.js:265:13)
at loadModule (node.js:231:20)
at require (node.js:291:14)
...
查看 resolveModuleFilename() 的源代码,它尝试打印一个调试字符串,但我没有看到:
debug("looking for " + JSON.stringify(id) + " in " + JSON.stringify(paths));
我已尝试通过 export NODE_DEBUG=1 启用此功能,但在尝试要求时我仍然看不到此调试打印。
我在尝试打印此调试时做错了什么?其次,为什么paperboy 可以正常加载,但是redis-client 找不到?
附加信息:这是“lib”目录中的完整文件/目录列表:
lib
lib/cookie-node
lib/cookie-node/package.json
lib/cookie-node/LICENSE.txt
lib/cookie-node/README.markdown
lib/cookie-node/example
lib/cookie-node/example/ex1.js
lib/cookie-node/index.js
lib/redis-client
lib/redis-client/package.json
lib/redis-client/TODO.md
lib/redis-client/examples
lib/redis-client/examples/redis-version.js
lib/redis-client/examples/using-kiwi.js
lib/redis-client/examples/subscriber.js
lib/redis-client/examples/publisher.js
lib/redis-client/examples/.redis-version.js.swp
lib/redis-client/examples/README.md
lib/redis-client/seed.yml
lib/redis-client/LICENSE
lib/redis-client/test
lib/redis-client/test/test_throw_from_callback.js
lib/redis-client/test/test_shutdown_reconnect.js
lib/redis-client/test/test.js
lib/redis-client/test/sample.png
lib/redis-client/.gitignore
lib/redis-client/lib
lib/redis-client/lib/redis-client.js
lib/redis-client/README.md
lib/paperboy
lib/paperboy/package.json
lib/paperboy/seed.yml
lib/paperboy/LICENSE.txt
lib/paperboy/example
lib/paperboy/example/basic.js
lib/paperboy/example/webroot
lib/paperboy/example/webroot/img
lib/paperboy/example/webroot/img/paperboy.jpg
lib/paperboy/example/webroot/index.html
lib/paperboy/index.js
lib/paperboy/lib
lib/paperboy/lib/paperboy.js
lib/paperboy/README.md
lib 目录是从 github 解压的 .tar.gz 文件,重新命名以匹配 package.json 文件中的模块名称。