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
相关产品推荐
相关产品推荐

