Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with adding fastify in Nest plugin #6915

Closed
mo0om opened this issue Sep 1, 2021 · 3 comments
Closed

Issue with adding fastify in Nest plugin #6915

mo0om opened this issue Sep 1, 2021 · 3 comments
Assignees
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx type: bug

Comments

@mo0om
Copy link

mo0om commented Sep 1, 2021

Current Behavior

I have a Nest.js app inside my NX repo.
I'm trying to bundle main.js for production and i'm getting this error
fastify not found, proceeding anyway

I'm not getting this error when I'm serving the app in dev mode.

// main.ts
// inside bootstrap()
...
 const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter())
...
  await app.listen(port, '0.0.0.0', () => {
    Logger.info({
      message: 'Listening at http://localhost:' + port + '/' + globalPrefix
    })
  })
// angular.json
"production": {
              "optimization": true,
              "outputHashing": "all",
              "extractLicenses": true,
              "inspect": false,
              "namedChunks": true,
              "aot": true,
              "vendorChunk": true,
              "buildOptimizer": true,
              "externalDependencies": [
                "@nestjs/microservices",
                "@nestjs/microservices/microservices-module",
                "@nestjs/websockets/socket-module",
                "cache-manager",
                "class-transformer",
                "class-validator",
                "class-transformer/storage"
              ]
// webpack.config.ts
const webpack = require('webpack')

const SwaggerPluginOptions = {
  dtoFileNameSuffix: ['.dto.ts', '.entity.ts', '.view.ts'],
  classValidatorShim: true,
  introspectComments: true
}

module.exports = (config, _context) => {
  config.module.rules
    .filter((rule) => rule.loader.includes('ts-loader'))
    .forEach((tsRule) => {
      tsRule.options = { ...tsRule.options }
      tsRule.options.transpileOnly = false
      tsRule.options.getCustomTransformers = addSwaggerPluginTransformer(tsRule.options.getCustomTransformers)
    })

  config.plugins = [
    ...(config.plugins || []),
    new webpack.ProvidePlugin({
      openapi: '@nestjs/swagger'
    })
  ]
  return config
}

function addSwaggerPluginTransformer(prevGetCustomTransformers) {
  return (program) => {
    const customTransformers = { ...(prevGetCustomTransformers ? prevGetCustomTransformers(program) : undefined) }
    customTransformers.before = [
      require('@nestjs/swagger/plugin').before(SwaggerPluginOptions, program),
      ...(customTransformers.before || [])
    ]
    return customTransformers
  }
}

Expected Behavior

Expect fastify to be bundled inside main.js

Failure Logs

fastify not found, proceeding anyway

Environment

nx report
nx : Not Found
@nrwl/angular : 10.0.12
@nrwl/cli : 10.0.12
@nrwl/cypress : 10.0.12
@nrwl/eslint-plugin-nx : 12.8.0
@nrwl/express : Not Found
@nrwl/jest : 10.0.12
@nrwl/linter : 11.6.0
@nrwl/nest : 12.8.0
@nrwl/next : Not Found
@nrwl/node : 12.8.0
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.8.0
@nrwl/web : Not Found
@nrwl/workspace : 10.0.12
typescript : 3.9.7

"@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/platform-fastify": "^7.0.0",
"@nestjs/swagger": "4.8.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"fastify-swagger": "^4.8.4",

@mo0om mo0om added the type: bug label Sep 1, 2021
@leosvelperez leosvelperez added the scope: node Issues related to Node, Express, NestJS support for Nx label Sep 3, 2021
@nartc
Copy link
Contributor

nartc commented Nov 11, 2021

@mo0om sorry for the late response. Can you provide a reproduce sample?

@nartc nartc self-assigned this Nov 11, 2021
@nartc
Copy link
Contributor

nartc commented Feb 15, 2022

It has been 3 months. If you can create a simple reproduce, please create a new issue.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: node Issues related to Node, Express, NestJS support for Nx type: bug
Projects
None yet
Development

No branches or pull requests

3 participants