Reputation: 410
I'm trying to add Swagger to my Nestjs app. Module not found error is thrown when I'm trying to compile it. I use the same code from Nestjs documentation. This is my 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();
This is the error:
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)
I'm using Node 14.15.1, @nestjs/swagger 5.0.0, swagger-ui-express: 4.1.6
Upvotes: 13
Views: 9495
Reputation: 23
In case anyone else gets this same problem but everything seems to be correct(Dockerfile), check for occurence in both devDependencies and normal dependencies, for me that was the cause of the issue, you need to remove it from devDependencies if you want to have it in prod(I had it in both).
Upvotes: 0
Reputation: 1087
Quick Fix ====>>
Update your dependencies to reflect:
{
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^1.1.5",
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
}
Update your dev dependencies to reflect:
{
"@nestjs/cli": "^8.0.0",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.0",
}
This fixed my problem. Let me know if this works for you!
Upvotes: 1
Reputation: 273
Swagger v5 is compatible with Nest v8 (@nestjs/core@^8.0.0, @nestjs/common@^8.0.0 etc) Swagger v4 is compatible with Nest v7
Source from https://github.com/nestjs/nest/issues/7499
Upvotes: 11
Reputation: 410
Update latest version of @nestjs/platform-express, @nestjs/common,@nestjs/core (8.0.0) solve my problem. It seems like nestjs/cli uses previous version of nestjs
Upvotes: 18