2

Here is my configuration

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule} from "@nestjs/swagger";

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

const config = new DocumentBuilder().setTitle("DNXT API")
.setDescription("The DNXT api is De generation next api")
.setVersion("1.0.0").build();

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup("/", app, document);
await app.listen(3000);
}
bootstrap();

while trying to run the app, i get the error below

(node:1612) UnhandledPromiseRejectionWarning: TypeError: shared_utils_1.validatePath is 
not a function
at SwaggerExplorer.validateRoutePath (C:\Users\HP\Desktop\DNXT\nest- 
ncc\node_modules\@nestjs\swagger\dist\swagger-explorer.js:135:61)
at SwaggerExplorer.generateDenormalizedDocument (C:\Users\HP\Desktop\DNXT\nest- 
ncc\node_modules\@nestjs\swagger\dist\swagger-explorer.js:53:25)
at SwaggerExplorer.exploreController (C:\Users\HP\Desktop\DNXT\nest- 
ncc\node_modules\@nestjs\swagger\dist\swagger-explorer.js:47:21)
at C:\Users\HP\Desktop\DNXT\nest-ncc\node_modules\@nestjs\swagger\dist\swagger- 
scanner.js:48:84
at Array.map (<anonymous>)
at SwaggerScanner.scanModuleRoutes (C:\Users\HP\Desktop\DNXT\nest- 
ncc\node_modules\@nestjs\swagger\dist\swagger-scanner.js:48:56)
at C:\Users\HP\Desktop\DNXT\nest-ncc\node_modules\@nestjs\swagger\dist\swagger- 
scanner.js:39:25
at Array.map (<anonymous>)
at SwaggerScanner.scanApplication (C:\Users\HP\Desktop\DNXT\nest- 
ncc\node_modules\@nestjs\swagger\dist\swagger-scanner.js:25:43)
at Function.createDocument (C:\Users\HP\Desktop\DNXT\nest- 
ncc\node_modules\@nestjs\swagger\dist\swagger-module.js:19:41)
(node:1612) UnhandledPromiseRejectionWarning: 

Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the

Fjay
  • 77
  • 9

2 Answers2

3

I finally was able to resolve the problem, apparently it was @nestjs/swagger version compatibility problem.

When you install @nestjs/swagger using npm install, it automatically install the recent version which is version 6 and it was not working with nestjs current version 9.0.0

So the issue was solved when install an older version 5 using this command below:

npm install @nestjs/swagger@5 sawgger-ui-express@4.5

Then it resolved the problem/issue of

(node:1612) UnhandledPromiseRejectionWarning: TypeError: shared_utils_1.validatePath is not a function problem
Fjay
  • 77
  • 9
0

Change this line

SwaggerModule.setup("/", app, document);

to

SwaggerModule.setup("/docs", app, document);

If that not worked create your project again, because the problem is about the version of the packages based on this issue:

https://github.com/nestjs/nest/issues/6115

Mohammad Yaser Ahmadi
  • 4,664
  • 3
  • 17
  • 39
  • Still not working, however after investigating the issue on https://github.com/nestjs/nest/issues/6115 , I discovered that is not similar, this is TypeError: shared_utils_1.addLeadingSlash is not a function #6115 while the error on my question is TypeError: shared_utils_1.validatePath is not a function (1612) – Fjay Jul 22 '22 at 05:40