gulpjs / rechoir

Prepare a node environment to require files with different extensions.
MIT License
48 stars 12 forks source link

throw new Error('No module loader found for "'+ext+'".'); #24

Closed alansouzati closed 9 years ago

alansouzati commented 9 years ago

I have a scenario where my file name has the following format filename.tmp.js.

The extension from rechoir is .tmp.js where I was expecting that to be .js.

I believe because of that we can't find the corresponding module loader for this file.

tkellen commented 9 years ago

Are you trying to use rechoir directly, or via another tool like Liftoff?

alansouzati commented 9 years ago

Via another tool with Liftoff.

tkellen commented 9 years ago

cc @phated

tkellen commented 9 years ago

Which tool?

This is unfortunate, but I believe you'll need to use the cli's --require flag to manually load babel in this instance. Most people who use Liftoff map extensions to loaders using this: https://github.com/tkellen/js-interpret/blob/master/index.js.

I don't see a sane path forward to supporting any arbitrary extensions that can "just work".

alansouzati commented 9 years ago

Thanks for your fast follow-up on this @tkellen, but, in your opinion, what is the extension of this file testing.tmp.js ? For me, I was expecting that to be .js. The current way you guys are loading the extensions it treats as tmp.js (I believe you guys did that because of the .babel.js convention).

If .js is the extension of testing.tmp.js then we don't have any arbitrary extensions. Unless you judge differently, which then I will treat the issue with the other library and verify if they can change to testing-tmp.js or something like that.

In my opinion, this library has to support this, but I'm probably not very much experienced to argue further.

phated commented 9 years ago

@tkellen I think we need to check extensions recursively. Let me think about this some more.

alansouzati commented 9 years ago

Yeah, @phated: the Pull Request that I sent tried to do that in a poor way. The PR is #25.

I've changed the regex a little bit and return, instead of a single extension, an array of possible extensions.

Hopefully this will help you guys to figure out something better than what I did.

tkellen commented 9 years ago

@alansouzati Sorry for closing your PR so soon. I think the approach you were taking was very close to what we should do.

If you can re-implement and have the extension checking break on the first match I'd be happy to merge this (with tests)!

alansouzati commented 9 years ago

No problem @tkellen, I will re-implement. I'm assuming I should send a new PR, right?

tkellen commented 9 years ago

Yes please.

seethroughdev commented 9 years ago

I'm getting the same error as well, using liftoffjs after updating. However, I'm getting it with 'rc' and no extension:

const cli = new Liftoff({
  name: 'crawler',
  extensions: objectAssign({'rc': null}, interpret.jsVariants),
  configName: '.crawler',
  v8flags: v8flags
});

I tried testing with @alansouzati new PR. I still have the same issue with only a slightly different message:

throw new Error('No module loader found for "'+usedExtension+'".');
          ^
Error: No module loader found for ".crawlerrc".

I hope this helps. If I use any of the other extensions, it works as expected. But of course, I built it with 'rc' in mind.

Thanks in advance.

silkentrance commented 9 years ago

@seethroughtrees Please note that all extensions must include the leading dot, i.e. ".rc" instead of just "rc".

tkellen commented 9 years ago

@seethroughtrees Crap. That is a regression. We need to add the full filename as the first option in #26.

seethroughdev commented 9 years ago

Thanks @tkellen

tkellen commented 9 years ago

This is partially resolved in 0.6.2. Filenames like dist.configfile.js or .configfilerc will work. We still haven't resolved compound extensions like configfile.tmp.js tho.

tkellen commented 9 years ago

@seethroughtrees Can you confirm this is working for .configrc files?

seethroughdev commented 9 years ago

Just got a chance to test. worked great with .configrc... Thanks for the work!

tkellen commented 9 years ago

@alansouzati This should be working now. I fixed it in https://github.com/tkellen/js-rechoir/commit/62fb2a62b6102f9ba07a05c7380ce237bb47b349.

alansouzati commented 9 years ago

cool thanks @tkellen . Just to make sure I understood correctly, the fix is where you add the nothrow option?

And is nothrow true by default or I need to provide a configuration for that?

tkellen commented 9 years ago

Yeah. This works because you're not using a special module loader (and also fixes the situation with files like .configrc). What it doesn't address (and I'm not sure that I want to address) is solving compound extensions that require a loader (like .coffee.babel.js or something).

alansouzati commented 9 years ago

Gotcha you. Awesome thanks man.

tkellen commented 9 years ago

Sure thing! I'm going to dig in using your PR in a min to see if I can fix the rest of this stuff.