pgriess / node-webworker

A WebWorkers implementation for NodeJS
BSD 3-Clause "New" or "Revised" License
646 stars 84 forks source link

Cannot use relative paths when requiring from within workers (e.g. require('./module')) #11

Closed bentomas closed 14 years ago

bentomas commented 14 years ago

This would be useful!

pgriess commented 14 years ago

It would be useful :)

But I don't think it's possible for a function in another module to know what the parent's __dirname value is. AFAICT require() has special support for this by virtue of really being a unique function instance for each module that it's injected into. Each private require() instance knows about the path of the module that it's supporting.

Check out Module.prototype._compile() in src/node.js.

I'm closing this, but please re-open if you come up with a clever way to achieve this. I'd love to support this syntax.

bentomas commented 14 years ago

Ahhh, yes I think you are right. Shucks. Well, it isn't too big of a deal, I just use postMessage to tell the child script its location and then have the child script require things using its location to create an absolute path.

Keep up the good work!