我正在更新我的node.js代码(http://ushomeautomation.com/Projects/node-irrigation/sched.js,有问题的代码靠近文件的顶部),这是我的第一个模块它通过以下方式安装:node.js:错误:无法找到模块'./Etherio'
npm install --save git+https://[email protected]/linuxha/Etherio.git
Etherio代码也在开发中。这工作:
var Etherio = require('/home/njc/dev/irrigation/irrnode/node_modules/Etherio');
但这并不:
var Etherio = require('./Etherio');
而且我的意思的作品是代码运行和灯光建兴上来就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
我是否缺少明显的东西?
的Debian的Linux(3.16.36-1 + deb8u1 x86_64的)
NPM(3.3.12)
节点(V5.2.0)
这似乎只是一个路径问题,我不太明白你的目录结构。但是,'要求(” ./ Etherio ');'在模块的代码当前正在运行的模块的同一个目录中查找模块,并且它只能在那个目录中查找,如果Etherio在'n ode_modules“,然后使用'require('Etherio');'。 – jfriend00
感谢改变它需要('Etherio');解决了这个问题。我以为'./'告诉node.js搜索直接的node_modules目录(Etherio.js位于node_modules/Etherio目录下) –