Open sgravrock opened 1 year ago
This is a great issue. I unfortunately don't know the answer because I'm not familiar with the ESM side of quibble. @giltayar may know if it's possible to detect this is the cause and fire our own exception that looks like the real one
Normally, Node throws an error with code
ERR_MODULE_NOT_FOUND
when the requested module is not found. But when the testdouble ESM loader is used, an error with codeENOENT
is thrown instead:I ran into this when documenting ways to mock ES modules with Jasmine. Jasmine tries to distinguish between a configuration file not existing and other types of errors loading a config file by checking the error code. The testdouble loader breaks that check, and that combined with another bug (jasmine tries to load jasmine.js even if jasmine.json is present) means that Jasmine doesn't work with the Testdouble loader if the default jasmine.json config file is used. I have a workaround that will ship in Jasmine 5.1.0, but the same problem could come up with other tools.
I'm not sure if this is fixable or not. My guess is that Node expects that a loader's
resolve
method will only return URLs referring to files that exist, but that approach seems like it could cause problems when multiple loaders are chained together.(edited to fix some confusing copypasta)