2016-11-29 13 views
0

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ボード(上にliteのことですに)。

~/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のDebian(3.16.36-1 + deb8u1 x86_64で)

NPM(3.3.12)

ノード(V5.2.0)

+1

使用しています。しかし、 '必要(」./ Etherio '); '現在のコードが実行されているモジュールと同じディレクトリにあるモジュールを探し、そのディレクトリでのみ見えるEtherioが' n ode_modules'を現在のモジュールディレクトリの下に置き、 'require( 'Etherio');'を使用します。 – jfriend00

+0

これを変更していただきありがとうございます( 'Etherio');問題を修正しました。私は './'がnode.jsに直接node_modulesディレクトリを検索するように指示したと考えました(Etherio.jsはnode_modules/Etherioディレクトリの下にあります)。 –

答えて

0

それは解決以来の答えに私のコメントを作ります問題:

これは単なるパスの問題のようです。

私はディレクトリ構造をよく理解していませんが、require('./Etherio');は、現在実行中のコードと同じディレクトリ内のモジュールを探し、そのディレクトリ内でのみ表示されます(下のnode_modulesディレクトリは見えません)。 Etherioは、現在のモジュールディレクトリの下のnode_modulesである場合

、そしてちょうど、私は非常にあなたのディレクトリ構造を理解していない。これは単なるパスの問題のように見えるrequire('Etherio');

+0

私のために解決してくれて大変ありがとうございます。私はrequire( './ package')とrequire( 'package')の意味を誤解していました。私も答えに投票しましたが、評判は低く、一般に公開されていません。 –

関連する問題