question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tutorial seems to be broken

See original GitHub issue

I’m having issues with initializing swagger module.

My server.ts file:

import { NestFactory } from '@nestjs/core';
import { json } from 'body-parser';
import { ApplicationModule } from './modules/app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create(ApplicationModule);
  app.use(json());

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

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

And i have following result:

[Nest] 2632   - 2017-12-6 19:38:42   [ExceptionHandler] app.use() requires a middleware function
TypeError: app.use() requires a middleware function
    at Function.use (D:\Learning\nest\project\node_modules\express\lib\application.js:210:11)
    at NestApplication.use (D:\Learning\nest\project\node_modules\@nestjs\core\nest-application.js:103:22)
    at exceptions_zone_1.ExceptionsZone.run (D:\Learning\nest\project\node_modules\@nestjs\core\nest-factory.js:107:48)
    at Function.run (D:\Learning\nest\project\node_modules\@nestjs\core\errors\exceptions-zone.js:16:13)
    at Proxy.args (D:\Learning\nest\project\node_modules\@nestjs\core\nest-factory.js:106:54)
    at Function.setup (D:\Learning\nest\project\node_modules\@nestjs\swagger\swagger-module.js:11:13)
    at D:\Learning\nest\project\server\server.ts:17:17
    at Generator.next (<anonymous>)
    at fulfilled (D:\Learning\nest\project\server\server.ts:4:58)
    at <anonymous>
(node:2632) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Unhandled Runtime Exception.
(node:2632) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero
 exit code.

Line 17 is where i call SwaggerModule.setup('/api', app, document)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chymzcommented, Dec 8, 2017

Same problem here !

I’ve a workarround :

import { NestFactory } from '@nestjs/core';
import * as express from 'express';
import * as SwaggerUI from 'swagger-ui-express';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
  const server = express();
  const app = await NestFactory.create(ApplicationModule, server);

  const options = new DocumentBuilder()
    .setTitle('Sample API')
    .setDescription('Sample API')
    .setVersion('1.0')
    .addTag('sample-api')
    .build();
  const document = SwaggerModule.createDocument(app, options);

  // Here use express instance directly
  server.use('/api', SwaggerUI.serve, SwaggerUI.setup(document));

  await app.listen(3000);
}

bootstrap()
  .then(() => {
    console.log('Application is listening on port 3000');
  })
  .catch((err) => {
    console.error(err);
  });
0reactions
lock[bot]commented, Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The tutorial seems to be broken? · Discussion #862 - GitHub
I noticed some of the links in the tutorial return a 404 error. For example https://openlayers.org/en/v4.5.0/build/ol.js. On the other hand, changing 4.5.0 ...
Read more >
the tutorial seems broken / quick-start/designing-your-first-api
While the tutorial may not be broken, it gives every appearance of being broken. It has a link to Design Center that instead...
Read more >
The Flutter Cupertino app tutorial seems to be broken
The Flutter Cupertino app tutorial seems to be broken ... Is it a problem with the tutorial or am I missing something?
Read more >
Tutorial seems broken :: Kingspray Graffiti General Discussions
Tutorial seems broken. Guy keeps telling me to teleport to the spot I'm already sitting in. Keeps telling me to teleport, But I'm...
Read more >
Solved: Re: Images in this tutorial seem to be broken - 180019
Images in this tutorial seem to be broken. Labels: Labels: Hortonworks Data Platform (HDP) · ssen. Contributor. Created ‎03-29-2017 09:10 PM.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found