Repository navigation
fix(core): name dynamic host modules in import error messages - #17939
Merged
kamilmysliwiec merged 3 commits intoSep 30, 2026
Merged
Conversation
When a module imported in its dynamic form (`forRoot()`, `register()`) has an `undefined` or invalid entry in its `imports`, the scanner passes the `DynamicModule` object as the parent. `UNDEFINED_MODULE_MESSAGE` and `INVALID_MODULE_MESSAGE` read `parentModule?.name`, which a plain object does not have, so the message said "Nest cannot create the module instance" and hid which module has the broken import. Use the existing `getInstanceName()` helper, which already resolves dynamic modules and forward references for the scope line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
A module whose
importsarray containsundefined(usually a circular file import) or an invalid value makes the scanner throwUndefinedModuleExceptionorInvalidModuleException. The message names the module that owns the brokenimportsarray:When that module is imported in its dynamic form (
CatsModule.forRoot(),register(), anyDynamicModule), the scanner passes theDynamicModuleobject as the parent.UNDEFINED_MODULE_MESSAGEandINVALID_MODULE_MESSAGEreadparentModule?.name, which the object does not have, so the message becomes:The name of the module to fix is gone, and the
Scope [...]line lists only its ancestors.The new specs against the current
messages.ts:Issue Number: N/A
What is the new behavior?
Both messages use the
getInstanceName()helper thatmessages.tsalready uses for the scope line. It resolves the class of aDynamicModuleand of a forward reference, so the dynamic case prints the same message as the static one.'module'stays as the fallback when no name can be found.Does this PR introduce a breaking change?
Other information
npx vitest run packages/core: 1392 passed.