aseemk / requireDir

Node.js helper to require() directories.
MIT License
484 stars 60 forks source link

"Cannot read property 'filename' of undefined" on require('require-dir') #34

Closed maqqju closed 8 years ago

maqqju commented 8 years ago

I am trying to get the requireDir by calling require('require-dir') and am getting the following error:

"Cannot read property 'filename' of undefined".

For some reason, my module.parent is always being undefined - hence the problem.

Am I trying to require requireDir in the wrong context?

aseemk commented 8 years ago

Hmm, that's indeed unexpected. Can you describe how you're running this?

Also, node --version, npm ls require-dir, OS, etc. would be helpful.

maqqju commented 8 years ago

Windows 8.1, Node v0.10.29, Require-Dir@0.3.0

aseemk commented 8 years ago

How are you requiring it?

maqqju commented 8 years ago

var requireDir = require('require-dir');

It is breaking on that line.

maqqju commented 8 years ago

Any updates on this please?

aseemk commented 8 years ago

Sorry about that — I missed your earlier reply.

Can you provide some more context? E.g. is this running in a file, or the REPL? Are you doing anything else with require? (E.g. overriding require.main or patching require in any other way?) Are you using any other module that does something with require AFAYK? Can you paste the whole stack trace?

I'm definitely grasping at straws here, because I've never heard of this error before. And the Travis CI tests even cover Node 0.10, so it wouldn't be that. I don't know about Windows though...

maqqju commented 8 years ago

I am trying to write an app - so far it is very simple: just an app.js hooked to an index.html and inside the app.js I am requiring the package.

As I said - the error is being thrown when requiring the package. Seems odd to me too - however I have no patches or overrides.

aseemk commented 8 years ago

Ah, you're running this browser-side? requireDir is only supported on Node.js (server-side). Sorry if that was unclear in the readme. (Feedback welcome on how that could be made more clear.)

Let me know if I misunderstood.

aseemk commented 8 years ago

Also, if I misunderstood, it might be most helpful if you could just share a GitHub Gist or similar with your code.

maqqju commented 8 years ago

Hi @aseemk - thanks for that! Yes I was trying to use it from a browser.

Thanks for your time.

aseemk commented 8 years ago

No problem! It might be possible to support the browser, but we can discuss that in issue #7. =)