title: NestJS/Swagger error TS2307: Cannot find module '@nestjs/swagger'
body: <p>I am trying to add Swagger in my NestJS app, yet I keep receiving an error that it cannot find the module. I have used <code>npm install --save @nestjs/swagger swagger-ui-express</code> to add it to the package.json file. Please note that I am also using docker with docker-compose.</p>
  
  <p>main.ts file:</p>
  
  <pre><code>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 whitelistOrigins = process.env.ALLOWED_CORS_ORIGIN;
    app.enableCors({
      origin: (origin, callback) =&gt; {
        if (whitelistOrigins.indexOf(origin) !== -1) {
          callback(null, true);
        } else {
          callback(null, false);
        }
      },
      optionsSuccessStatus: 200,
    });
  
  
    const options = new DocumentBuilder()
      .setTitle('App')
      .setDescription('The App API;')
      .setVersion('1.0')
      .addTag('app')
      .build();
    const document = SwaggerModule.createDocument(app, options);
    SwaggerModule.setup('api', app, document);
  
    await app.listen(process.env.PORT);
  }
  bootstrap();
  </code></pre>
  
  <p>package.json file:</p>
  
  <pre><code>"dependencies": {
      "@nestjs/common": "^6.3.1",
      "@nestjs/core": "^6.3.1",
      "@nestjs/jwt": "^6.1.1",
      "@nestjs/mongoose": "^6.1.2",
      "@nestjs/passport": "^6.1.0",
      "@nestjs/platform-express": "^6.3.2",
      "@nestjs/platform-socket.io": "^6.3.2",
      "@nestjs/swagger": "^3.1.0",
      "@nestjs/websockets": "^6.3.1",
      "bcrypt": "^3.0.6",
      "cache-manager": "^2.9.1",
      "cache-manager-redis-store": "^1.5.0",
      "dotenv": "^8.0.0",
      "google-auth-library": "^4.2.2",
      "helmet": "^3.21.1",
      "joi": "^14.3.1",
      "lodash": "^4.17.11",
      "moment": "^2.24.0",
      "mongoose": "^5.6.0",
      "nest-access-control": "^2.0.1",
      "nest-schedule": "^0.6.0",
      "passport": "^0.4.0",
      "passport-http-bearer": "^1.0.1",
      "passport-jwt": "^4.0.0",
      "reflect-metadata": "^0.1.13",
      "rimraf": "^2.6.3",
      "rxjs": "^6.5.2",
      "socket.io-redis": "^5.2.0",
      "swagger-ui-express": "^4.1.2",
      "typescript": "^3.5.2"
    },
    "devDependencies": {
      "@nestjs/testing": "^6.3.1",
      "@types/express": "^4.17.0",
      "@types/jest": "^24.0.15",
      "@types/node": "^12.0.8",
      "@types/supertest": "^2.0.7",
      "jest": "^24.8.0",
      "nodemon": "^1.19.1",
      "prettier": "^1.18.2",
      "supertest": "^4.0.2",
      "ts-jest": "^24.0.2",
      "ts-loader": "^6.0.3",
      "ts-node": "^8.3.0",
      "tsconfig-paths": "^3.8.0",
      "tslint": "5.17.0"
    },
  </code></pre>
  
  <p>tsconfig.json file:</p>
  
  <pre><code>{
    "compilerOptions": {
      "module": "commonjs",
      "declaration": true,
      "removeComments": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "target": "es6",
      "sourceMap": true,
      "outDir": "./dist",
      "baseUrl": "./",
      "moduleResolution": "node"
    },
  }
  </code></pre>
  
  <p>I keep receiving the following error while running the app using <code>npm run start:dev</code> and <code>npm run start:prod</code>:</p>
  
  <pre><code>/home/node/app/node_modules/ts-node/src/index.ts:293
       return new TSError(diagnosticText, diagnosticCodes)
              ^
   TSError: ⨯ Unable to compile TypeScript:
   src/main.ts(4,48): error TS2307: Cannot find module '@nestjs/swagger'.
  
       at createTSError (/home/node/app/node_modules/ts-node/src/index.ts:293:12)
       at reportTSError (/home/node/app/node_modules/ts-node/src/index.ts:297:19)
       at getOutput (/home/node/app/node_modules/ts-node/src/index.ts:399:34)
       at Object.compile (/home/node/app/node_modules/ts-node/src/index.ts:457:32)
       at Module.m._compile (/home/node/app/node_modules/ts-node/src/index.ts:530:43)
       at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
       at Object.require.extensions.(anonymous function) [as .ts] (/home/node/app/node_modules/ts-node/src/index.ts:533:12)
       at Module.load (internal/modules/cjs/loader.js:653:32)
       at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
       at Function.Module._load (internal/modules/cjs/loader.js:585:3)
   [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>
  
  <p>docker-compose.yml file:</p>
  
  <pre><code>version: "2"
  services:
    node:
      build: 
        context: .
        dockerfile: ./docker/node/Dockerfile
      user: "node"
      working_dir: /home/node/app
      environment:
        - NODE_ENV=development
      volumes:
        - ./:/home/node/app
        - /home/node/app/node_modules/
      expose:
        - "8081"
      command: "npm run start:dev"
      ports:
        - "8000:8000"
      depends_on:
        - mongo
        - redis
    mongo:
      image: mongo
      ports:
        - "27018:27017"
      volumes:
        - data-volume:/data/db
    redis:
      image: redis
      ports:
        - "6379:6379"
    mongoclient:
      image: mongoclient/mongoclient:2.2.0
      depends_on:
        - mongo
      ports:
        - 3300:3000
  volumes:
    data-volume:
  </code></pre>
  
  <p>/docker/node/Dockerfile:</p>
  
  <pre><code>FROM node:10
  
  WORKDIR /home/node/app
  COPY ./package.json ./
  
  RUN npm install nodemon -g
  RUN npm install
  </code></pre>
  
  <p>This error is received while using nodemon.</p>