You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NestJS编译报错TS2304:找不到名称'Get'

解决TypeScript编译错误TS2304: Cannot find name 'Get'

这个错误的核心原因是你在代码中使用了@Get()路由装饰器,但未从@nestjs/common包中显式导入它。NestJS的所有装饰器都需要手动导入才能正常使用。

解决方案

修改导入语句,将Get添加到导入列表中:

import {Controller, Module, Get } from "@nestjs/common";

修正后的完整代码

import {Controller, Module, Get } from "@nestjs/common";
import {NestFactory} from "@nestjs/core";
@Controller()
class AppController {
    @Get()
    getRootRoute() {
        return "Hi, there!";
    }
}

@Module({
    controllers: [AppController]
})
class AppModule {}

async function bootstrap() {
    const app = await NestFactory.create(AppModule);

    await app.listen(3000);
}
bootstrap()

内容的提问来源于stack exchange,提问作者Taimur Ajmal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 23:20:33