nestjs/nest · error · UndefinedForwardRefException
Nest cannot create the module instance. Often, this is becau
Error message
Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it.
(Read more: https://docs.nestjs.com/fundamentals/circular-dependency)
Scope [${scope}]
What it means
Error "Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it. (Read more: https://docs.nestjs.com/fundamentals/circular-dependency) Scope [${scope}] " thrown in nestjs/nest.
Source
Thrown at packages/core/injector/container.ts:106
public getHttpAdapterHostRef() {
return this.internalProvidersStorage.httpAdapterHost;
}
public async addModule(
metatype: ModuleMetatype,
scope: ModuleScope,
): Promise<
| {
moduleRef: Module;
inserted: boolean;
}
| undefined
> {
// In DependenciesScanner#scanForModules we already check for undefined or invalid modules
// We still need to catch the edge-case of `forwardRef(() => undefined)`
if (!metatype) {
throw new UndefinedForwardRefException(scope);
}
const { type, dynamicMetadata, token } =
await this.moduleCompiler.compile(metatype);
if (this.modules.has(token)) {
return {
moduleRef: this.modules.get(token)!,
inserted: false,
};
}
return {
moduleRef: await this.setModule(
{
token,
type,
dynamicMetadata,
},
scope,View on GitHub (pinned to dd75d7bd8c)
When it happens
Trigger: Thrown at packages/core/injector/container.ts:106 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of nestjs/nest@dd75d7bd8c (2026-08-21).
Data as JSON: /api/errors/8dc09c73e51de280.
Report an issue: GitHub.