Skip to content

Fail missing, unmocked imports with ERR_MODULE_NOT_FOUND, not ENOENT - #129

Merged
rosston merged 1 commit into
mainfrom
fix-missing-module-error-100
Oct 12, 2026
Merged

rosston merged 1 commit into
mainfrom
fix-missing-module-error-100

Conversation

@rosston

@rosston rosston commented Oct 12, 2026

Copy link
Copy Markdown
Member

Fixes #100

So that missing modules can be mocked, recoverResolve turns Node's ERR_MODULE_NOT_FOUND into a made-up URL. When nothing mocks that URL, the load hook passed it to nextLoad, which threw ENOENT instead.

Save the resolve error and rethrow it from the load hook when the URL isn't mocked. It's keyed by the URL without its query, because on Node 26+ the registerHooks() hooks run alongside --loader=quibble and re-tag the URL before it reaches the off-thread load hook. A successful resolve of the same URL forgets the error, so a file created later still loads.

Fixes #100

So that missing modules can be mocked, recoverResolve turns Node's
ERR_MODULE_NOT_FOUND into a made-up URL. When nothing mocks that URL,
the load hook passed it to nextLoad, which threw ENOENT instead.

Save the resolve error and rethrow it from the load hook when the URL
isn't mocked. It's keyed by the URL without its query, because on Node
26+ the registerHooks() hooks run alongside --loader=quibble and re-tag
the URL before it reaches the off-thread load hook. A successful resolve
of the same URL forgets the error, so a file created later still loads.
@rosston rosston self-assigned this Oct 12, 2026
@rosston
rosston marked this pull request as ready for review October 12, 2026 15:15
@rosston

rosston commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

The only tests failing in the testdouble.js integration test are the ones asserting a ENOENT failure, which is what this PR changes. So it's fine that they are failing for this. I'll have them fixed when updating quibble in testdouble.js after this change.

@rosston
rosston merged commit b86a697 into main Oct 12, 2026
12 of 18 checks passed
@rosston
rosston deleted the fix-missing-module-error-100 branch October 12, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

import throws ENOENT instead of ERR_MODULE_NOT_FOUND when a module is not found

1 participant