#Nest can't resolve dependencies of the AppController

11 messages · Page 1 of 1 (latest)

west elm
#
[Nest] 25920  - 07/18/2025, 8:34:44 AM     LOG [NestFactory] Starting Nest application...
[Nest] 25920  - 07/18/2025, 8:34:44 AM   ERROR [ExceptionHandler] UnknownDependenciesException [Error]: Nest can't resolve dependencies of the AppController (?). Please make sure that the argument Function at index [0] is available in the AppModule context.

I'm not sure why it thinks that the dependency is Function.

app.module.ts

import { Module } from "@nestjs/common";

import { AppController } from "./app.controller";
import { AppService } from "./app.service";

@Module({
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}

app.service.ts

import { Injectable } from "@nestjs/common";

@Injectable()
export class AppService {
    async getHello() {
        return "Hello World";
    }
}

What am I doing wrong??

hushed moat
#

PLease show the controller file as well

#

And you tsconfig.json

west elm
#
import { Controller, Get } from "@nestjs/common";

import type { AppService } from "./app.service";

@Controller()
export class AppController {
    constructor(private readonly appService: AppService) {}

    @Get()
    async getHello() {
        return await this.appService.getHello();
    }
}

Thanks for looking

#
{
    "compilerOptions": {
        "module": "NodeNext",
        "moduleResolution": "NodeNext",
        "declaration": true,
        "declarationMap": true,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "target": "ES2023",
        "sourceMap": true,
        "outDir": "./dist",
        "baseUrl": "./",
        "incremental": true,
        "skipLibCheck": true,
        "strictNullChecks": true,
        "forceConsistentCasingInFileNames": true,
        "noImplicitAny": false,
        "strictBindCallApply": false,
        "noFallthroughCasesInSwitch": false
    }
}
hushed moat
#

import type here's your problem

#

typescript compiler removes all type imports

#

but they're needed for injection in order for emitDecoratorMetadata to work

west elm
#

I see

hushed moat
#

the actual import needs to be there at runtime, otherwise typescript won't generate the metadata that Nest can then use to fogure out what to inject

west elm
#

That's a keen eye... Thanks.