模块未找到嵌套和Swagger

1szpjjfi  于 2022-11-06  发布在  其他
关注(0)|答案(3)|浏览(216)

我尝试将Swagger添加到我的Nestjs应用程序中。当我试图编译它时,抛出了Module not found错误。我使用了Nestjs文档中的相同代码。这是我的main.ts:

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

  const config = new DocumentBuilder()
    .setTitle('Cats example')
    .setDescription('The cats API description')
    .setVersion('1.0')
    .addTag('cats')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);

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

这是错误:

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '@nestjs/core/router/route-path-factory'
Require stack:
- D:\BK\solidity\MVPApp\blockchain\back-end-student-wallet-v2\node_modules\@nestjs\swagger\dist\swagger-explorer.js
- D:\BK\solidity\MVPApp\blockchain\back-end-student-wallet-v2\node_modules\@nestjs\swagger\dist\swagger-scanner.js 
- D:\BK\solidity\MVPApp\blockchain\back-end-student-wallet-v2\node_modules\@nestjs\swagger\dist\swagger-module.js  
- D:\BK\solidity\MVPApp\blockchain\back-end-student-wallet-v2\node_modules\@nestjs\swagger\dist\index.js
- D:\BK\solidity\MVPApp\blockchain\back-end-student-wallet-v2\node_modules\@nestjs\swagger\index.js
- D:\BK\solidity\MVPApp\blockchain\back-end-student-wallet-v2\dist\main.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)

我正在使用节点14.15.1,@nestjs/swagger 5.0.0,swagger-ui-express:4.1.6

2q5ifsrm

2q5ifsrm1#

更新最新版本的@nestjs/platform-express,@nestjs/common,@nestjs/core(8.0.0)解决了我的问题。看起来nestjs/cli使用的是以前版本的nestjs

w8ntj3qf

w8ntj3qf2#

Swagger v5与Nest v8兼容(@nestjs/核心@^8.0.0、@nestjs/公用@^8.0.0等)Swagger v4与Nest v7兼容
来源于https://github.com/nestjs/nest/issues/7499

5t7ly7z5

5t7ly7z53#

快速修复====〉〉
更新依赖项以反映:

{
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^1.1.5",
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
}

更新您的开发依赖项以反映:

{
        "@nestjs/cli": "^8.0.0",
        "@nestjs/schematics": "^8.0.0",
        "@nestjs/testing": "^8.0.0",
    }

这解决了我的问题。让我知道这是否适合你!

相关问题