A question on usage of require

162 views
Skip to first unread message

Deva Kumaraswamy

unread,
Jul 10, 2014, 9:40:56 PM7/10/14
to nod...@googlegroups.com
I ran into install issues on Centos with one of the popular and useful packages ref.

when I do 
npm install ref

I get the following error: "Cannot find module '../'.

The offending line is
var gyp = require('../')

In my limited experience with nodejs I have never used this form of require.
What exactly is this supposed to resolve to?

Thanks the help.
Deva
===================
PS: part of the traceback.

npm install ref
 
> r...@0.3.2 install /sasusr/u/kumar/node_modules/ref
> node-gyp rebuild

\
module.js:340
    throw err;
          ^
Error: Cannot find module '../'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/sasusr/u/kumar/node-v0.10.29-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js:13:11)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
npm ERR! r...@0.3.2 install: `node-gyp rebuild`
npm ERR! Exit status 8


mscdex

unread,
Jul 11, 2014, 8:56:29 AM7/11/14
to nod...@googlegroups.com
On Thursday, July 10, 2014 9:40:56 PM UTC-4, Deva Kumaraswamy wrote:
when I do 
npm install ref

I get the following error: "Cannot find module '../'.


It installs fine for me on node v0.10.29. What node (`node -v`) and npm (`npm -v`) version are you using?

mgutz

unread,
Jul 11, 2014, 6:59:48 PM7/11/14
to nod...@googlegroups.com
require('../') means require parent directory's index.js. When a require path is a directory, node tries index.js.

Deva Kumaraswamy

unread,
Jul 12, 2014, 11:01:14 PM7/12/14
to nod...@googlegroups.com
Thanks. That is pretty nifty. However:
I do not see an index.js in the npm->node->modules->node-gyp directory or any of its sub directories. 
My directories on windows looks the same.
Still puzzled, 

Subnote: There is a node-gyp entry in the lib directory that exports the entries the failing code seems to be looking for. 

Ryan Graham

unread,
Jul 14, 2014, 1:39:23 AM7/14/14
to nodejs
It's only index.js by default. If there is a package.json in that directory it is used to look up the package's "main" entry point. It defaults to "index.js", but it is often something like "lib/<someclass>.js".

~Ryan

On Sat, Jul 12, 2014 at 8:01 PM, Deva Kumaraswamy <devakuma...@gmail.com> wrote:
Thanks. That is pretty nifty. However:
I do not see an index.js in the npm->node->modules->node-gyp directory or any of its sub directories. 
My directories on windows looks the same.
Still puzzled, 

Subnote: There is a node-gyp entry in the lib directory that exports the entries the failing code seems to be looking for. 


On Friday, July 11, 2014 6:59:48 PM UTC-4, mgutz wrote:
require('../') means require parent directory's index.js. When a require path is a directory, node tries index.js.


Deva Kumaraswamy

unread,
Jul 14, 2014, 8:56:58 AM7/14/14
to nod...@googlegroups.com
Ok. That makes sense.
I am checking thru the directories and comparing what I have on my Centos box with what is on my windows box. when I get into work,  I will run the debugger to see why it is failing - hpefully it is something as simple as permissions.:-)
thanks...

Deva Kumaraswamy

unread,
Jul 14, 2014, 10:44:56 PM7/14/14
to nod...@googlegroups.com
mscdex asked about my version. I am running 0.10.29 - the latest.
I did further investigation:  looking thru node-gyp issues  it looks like there are some unresolved issues related to permissions on Unix.
Just out of curiosity I moved the package.json from ./lib directory under node-gyp to the parent directory (node-gyp). The process got further but then it ran into an issue updating  /myroot/.node-gyp.
So overall, the explanation I got to my original question helped me understand how require works - thanks.
But as these things go I am still without an answer to my originalproblem - I will turn to the node-gyp issues on github seeking more information (although it looks like everyone is stymied by a variety of permission related issues on Linux). I might go looking for an Unix guru in my organization to help sort this out.

Thanks for the help.

Sam Roberts

unread,
Jul 15, 2014, 1:35:35 PM7/15/14
to nod...@googlegroups.com
On Mon, Jul 14, 2014 at 7:44 PM, Deva Kumaraswamy
<devakuma...@gmail.com> wrote:
> I will turn to the node-gyp issues on github seeking more information
> (although it looks like everyone is stymied by a variety of permission
> related issues on Linux). I might go looking for an Unix guru in my
> organization to help sort this out.

Might be a variant of:

https://github.com/npm/npm/issues/5637

You could try posting into that issue if this is reproduceable, if
more people poke this, it might get fixed.

And fwiw... I don't personally ever have permissions issues on Linux
:-), but I chmoded by /usr/local to be owned by my login, this is the
npm happy path, allowing installation into /usr/local without sudo.

Cheers,
Sam

Deva Kumaraswamy

unread,
Jul 16, 2014, 12:52:37 AM7/16/14
to nod...@googlegroups.com
yes - the problem seems related. I have seen variations of this issue reported - an example: .node-gyp cannot be accessed during the install. 
I will track your report also.
Reply all
Reply to author
Forward
0 new messages