LearnBoost / cluster

Node.JS multi-core server manager with plugins support.
http://learnboost.github.com/cluster
MIT License
2.29k stars 159 forks source link

Master unable to resolve local modules when main module is a directory #120

Closed coverslide closed 1 year ago

coverslide commented 13 years ago

Might be a known problem but ...

lets say i have a file hierarchy thus so:

/site/
  /index.js
  /lib/
    library.js
... etc

the contents of my index.js is something like

require('cluster')('./lib/library').listen(8080)

the following commands work:

node /site/index
node /site/index.js

the following commands do not work

node /site
node /site/

giving an error like so:

Error: Cannot find module '/./lib/library'
    at Function._resolveFilename (module.js:317:11)
    at Function._load (module.js:262:25)
    at require (module.js:346:19)
    at new Master (/srv/node/http-host/sites/default/node_modules/cluster/lib/master.js:150:19)
    at start (/srv/node/http-host/sites/default/node_modules/cluster/lib/cluster.js:42:10)

I get the same thing with package.json directories

A trivial problem, but nonetheless, i think cluster should be intelligent enough to solve this problem

tj commented 13 years ago

not sure I get it, what does this have to do with cluster? maybe best to post this in node's issue queue for require resolution

coverslide commented 13 years ago

Except for the fact that Master.resolve doesn't follow the standard require resolution. It tries to rebuild the server path using process.argv like so:

http://github.com/LearnBoost/cluster/blob/master/lib/master.js#L100

so it's not node that's fucking up. Probably would be better to use require.main.filename

tj commented 13 years ago

ah ok now I see what you mean, I agree, although it's essentially storing that arg in order to re-exec what originally executed so it should be resolved in the same manner