我正在更新我的node.js代码(http://ushomeautomation.com/Projects/node-irrigation/sched.js,所讨论的代码接近文件的顶部),这是我的第一个模块,它是通过以下方式安装的:
npm install --save git+https://git@github.com/linuxha/Etherio.gitEtherio代码也在开发中。这样做是可行的:
var Etherio = require('/home/njc/dev/irrigation/irrnode/node_modules/Etherio');但这并不是:
var Etherio = require('./Etherio');我所说的工作就是代码运行,以太板上亮起灯来(我的模块就是这么说的)。
~/dev/irrigation/irr-sched$ node ./sched.js
module.js:329
throw err;
^
Error: Cannot find module './Etherio'
at Function.Module._resolveFilename (module.js:327:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:355:17)
at require (internal/module.js:13:17)
at Object.<anonymous> (/home/njc/dev/irrigation/irr-sched/sched.js:70:15)
at Module._compile (module.js:399:26)
at Object.Module._extensions..js (module.js:406:10)
at Module.load (module.js:345:32)
at Function.Module._load (module.js:302:12)
at Function.Module.runMain (module.js:431:10)
~/dev/irrigation/irr-sched$ pwd
/home/njc/dev/irrigation/irr-sched
~/dev/irrigation/irr-sched$ ls -la node_modules/Etherio/
total 24
drwxr-xr-x 2 njc njc 4096 Nov 28 19:33 .
drwxr-xr-x 59 njc njc 4096 Nov 28 19:33 ..
-rw-r--r-- 1 njc njc 4183 Nov 28 19:33 Etherio.js
-rw-r--r-- 1 njc njc 2317 Nov 28 19:33 package.json
-rw-r--r-- 1 njc njc 90 Nov 28 19:33 README.md我漏掉了什么明显的东西吗?
Linux (3.16.36-1+deb8u1 x86_64)
国家预防机制(3.3.12)
节点(v5.2.0)
发布于 2016-11-29 02:54:13
自从它解决了这个问题之后,我的评论变成了一个答案:
这似乎只是一个路径问题。
我不太理解您的目录结构,但是require('./Etherio');在与其代码当前正在运行的模块所在的目录相同的目录中查找模块,并且只在该目录中查找(它不在下面的node_modules目录中查找)。
如果Etherio位于当前模块目录下的node_modules中,则只需使用require('Etherio');
https://stackoverflow.com/questions/40856225
复制相似问题