我有一个像这样的目录结构:
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));
我尝试通过导出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文件中的模块名称.
你想要出口NODE_DEBUG=module
,而不是=1