This error is caused by wrong CORS config. To fix it:

  • Update swagger by adding :
.addServer('http://localhost:3000')
  • Add origin in CORS config (the address you're using) :
app.enableCors({origin: 'http://localhost:3000'});
Answer from harian on Stack Overflow
🌐
GitHub
github.com › nestjs › swagger › blob › master › lib › document-builder.ts
swagger/lib/document-builder.ts at master · nestjs/swagger
* @deprecated Use `addServer` method to set up multiple different paths. The `setBasePath` method has been deprecated. Now, a global prefix is populated automatically. If you want to ignore it, take a look here: https://docs.nestjs.com/reci...
Author   nestjs
🌐
Medium
rehmat-sayany.medium.com › integrating-swagger-with-nestjs-a-step-by-step-guide-abd532743c43
Integrating Swagger with NestJS: A Step-by-Step Guide | by Rehmat Sayany | Medium
August 11, 2023 - Instead of just hosting, you have ... dropdown where we select the Server base URL. NestJS provides decorators that integrate seamlessly with Swagger to auto-generate documentation....
🌐
Medium
hafez-heybati.medium.com › install-swagger-in-nestjs-618732123fa1
Install swagger in NestJs. What Is OpenAPI? | by Hafez Heybati Goujani | Medium
January 3, 2024 - import { NestFactory } from '@nestjs/core'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); const options = new DocumentBuilder() .setTitle('API Title') .setDescription('API description') .setVersion('1.0') .addServer('http://localhost:3000/', 'Local environment') .addServer('http://staging URL/', 'Staging') .addServer('http://production URL/', 'Production') .addTag('API Tag') .build(); const document = SwaggerModule.createDocument(app, options); SwaggerModule.setup('api-docs', app, document); await app.listen(3000); } bootstrap(); With this setup, your Swagger UI will be available at http://localhost:3000/api-docs.
🌐
npm
npmjs.com › package › @nestjs › swagger
nestjs/swagger
2 weeks ago - Nest - modern, fast, powerful node.js web framework (@swagger). Latest version: 11.4.6, last published: 10 days ago. Start using @nestjs/swagger in your project by running `npm i @nestjs/swagger`. There are 2486 other projects in the npm registry using @nestjs/swagger.
      » npm install @nestjs/swagger
    
Published   Jul 17, 2026
Version   11.4.6
🌐
Devland
docs.devland.is › development › openapi
OpenAPI | Handbook - Technical Direction
April 2, 2024 - import { DocumentBuilder } from '@nestjs/swagger' export const openApi = new DocumentBuilder() .setTitle('IdentityServer Public API') .setDescription( 'Public API for IdentityServer.\n\n\nThe swagger document can be downloaded by appending `-json` to the last path segment.', ) .addServer(process.env.PUBLIC_URL ??
🌐
npm
npmjs.com › package › @nestjs › swagger › v › 7.3.1
@nestjs/swagger - npm
addServer · addApiKey · addBasicAuth · addSecurity · addSecurityRequirements · Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here. Author - Kamil Myśliwiec · Website - https://nestjs.com · Twitter - @nestframework · Nest is MIT licensed. none · npm i @nestjs/swagger@7.3.1 ·
      » npm install @nestjs/swagger
    
Published   May 05, 2025
Version   7.3.1
Author   Kamil Mysliwiec
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 76992483 › schemas-server-with-swagger-and-nestjs-how-can-i-add-this-schemas-example
typescript - Schemas server with Swagger and NestJs. how can i add this schemas example? - Stack Overflow
August 28, 2023 - const config = new DocumentBuilder() .setTitle('Your API') .setDescription('API documentation') .setVersion('1.0') .addTag('example') .addServer('http://localhost', 'HTTP') // HTTP scheme .addServer('https://localhost', 'HTTPS') // HTTPS scheme .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('openapi', app, document);
🌐
GitHub
github.com › nestjs › swagger
GitHub - nestjs/swagger: OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas: · GitHub
OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas: - nestjs/swagger
Author   nestjs
🌐
Medium
medium.com › @anshusharma98204 › integrating-swagger-with-nestjs-a-step-by-step-guide-b79db952ca0e
Integrating Swagger with NestJS: A Step-by-Step Guide | by Anshu Sharma | Medium
November 25, 2024 - import { NestFactory } from '@nestjs/core'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); const options = new DocumentBuilder() .setTitle('Your API Title') .setDescription('Your API description') .setVersion('1.0') .addServer('http://localhost:3000/', 'Local environment') .addServer('https://staging.yourapi.com/', 'Staging') .addServer('https://production.yourapi.com/', 'Production') .addTag('Your API Tag') .build();const document = SwaggerModule.createDocument(app, options); SwaggerModule.setup('api-docs', app, document);await app.listen(process.env.PORT || 3000); } bootstrap(); With this setup, your Swagger UI will be available at http://localhost:3000/api-docs.
🌐
Bitstack
blog.bitsrc.io › a-guide-to-nestjs-swagger-configuration-dec5f183b53
A Guide to NestJS Swagger Configuration | by Quokka Labs | Bits and Pieces
November 16, 2022 - Documentation is more important than you think and is essential to the whole application development process and back-end and front-end development. Generally, good API documentation is necessary for clients to use an API effectively. In this blog, we are doing a Swagger Configuration with NestJS, and we will learn how to configure it effectively.
🌐
NestJS
docs.nestjs.com › openapi › introduction
OpenAPI (Swagger) | NestJS - A progressive Node.js framework
This method takes two arguments, an application instance and a Swagger options object. Alternatively, we can provide a third argument, which should be of type SwaggerDocumentOptions.
🌐
NestJS
docs.nestjs.com › recipes › swagger
OpenAPI (Swagger) | NestJS - A progressive Node.js ...
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
🌐
PROGRESSIVE CODER
progressivecoder.com › home › blog › a guide to nestjs swagger configuration
A Guide to NestJS Swagger Configuration
March 17, 2023 - Learn about NestJS Swagger Configuration to enable OpenAPI compliant documentation and how to leverage the various configuration options
🌐
Yarn
yarnpkg.com › package
Yarn
Cannot read properties of null (reading 'startsWith')
🌐
Medium
medium.com › @andremazmol › using-swagger-with-nestjs-b94dae253613
Using swagger with NestJS. The documentation of APIs is crucial in… | by Andre Molinari | Medium
November 7, 2023 - The documentation of APIs is crucial in modern software development, and Swagger has become a go-to tool for creating elegant and interactive API documentation. In this article, we’ll explore how to integrate Swagger into a NestJS project. NestJS is a progressive Node.js framework for building efficient, reliable, and scalable server-side applications.
🌐
npm
npmjs.com › package › modified-nestjs-swagger
modified-nestjs-swagger - npm
November 5, 2020 - addServer · addApiKey · addBasicAuth · addSecurity · addSecurityRequirements · Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here. Author - Kamil Myśliwiec · Website - https://nestjs.com · Twitter - @nestframework · Nest is MIT licensed. none · npm i modified-nestjs-swagger ·
      » npm install modified-nestjs-swagger
    
Published   Nov 05, 2020
Version   4.6.4
Author   Kamil Mysliwiec