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

Unable to modify build step for nestjs with nx v19 #23236

Open
1 of 4 tasks
cre8 opened this issue May 8, 2024 · 5 comments
Open
1 of 4 tasks

Unable to modify build step for nestjs with nx v19 #23236

cre8 opened this issue May 8, 2024 · 5 comments
Assignees
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug

Comments

@cre8
Copy link

cre8 commented May 8, 2024

Current Behavior

In my nx v17 I was able to configure the build target to modify the options like adding the swagger pluging for nestjs:

{
  "executor": "@nx/webpack:webpack",
  "outputs": ["{options.outputPath}"],
  "defaultConfiguration": "production",
  "options": {
    "target": "node",
    "compiler": "tsc",
    "outputPath": "dist/apps/verifier-backend",
    "main": "apps/verifier-backend/src/main.ts",
    "tsConfig": "apps/verifier-backend/tsconfig.app.json",
    "assets": ["apps/verifier-backend/src/assets"],
    "isolatedConfig": true,
    "webpackConfig": "apps/verifier-backend/webpack.config.js",
    "transformers": [
      {
        "name": "@nestjs/swagger/plugin",
        "options": {
          "classValidatorShim": true,
          "introspectComments": true,
          "controllerKeyOfComment": "summary"
        }
      }
    ]
  },
  "configurations": {
    "development": {},
    "production": {}
  }
},

When I add this target to a nx v19 project, it will respect the plugin, but the serve command will not work anymore.

Expected Behavior

It would be nice to have more information how to update the correct build target or how to append the information for it.

GitHub Repo

No response

Steps to Reproduce

  1. create a fresh nx repo with a nest application
  2. add swagger plugin with the provided information

Nx Report

Node   : 20.12.2
OS     : win32-x64
pnpm   : 8.15.8

nx (global)        : 19.0.0
nx                 : 19.0.0
@nx/js             : 19.0.0
@nx/jest           : 19.0.0
@nx/eslint         : 19.0.0
@nx/workspace      : 19.0.0
@nx/angular        : 19.0.0
@nx/devkit         : 19.0.0
@nx/eslint-plugin  : 19.0.0
@nx/nest           : 19.0.0
@nx/node           : 19.0.0
@nx/playwright     : 19.0.0
@nx/vite           : 19.0.0
@nx/web            : 19.0.0
@nx/webpack        : 19.0.0
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin
@nx/playwright/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@cre8 cre8 added the type: bug label May 8, 2024
@AgentEnder AgentEnder added the scope: node Issues related to Node, Express, NestJS support for Nx label May 10, 2024
@Nazar-Brunarskyi
Copy link

i have the same problem

@cre8
Copy link
Author

cre8 commented May 13, 2024

@Nazar-Brunarskyi someone gave me a tip by adding the information to the webpack.config.ts like:

const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
const { join } = require('path');

module.exports = {
  output: {
    path: join(__dirname, '../../dist/apps/issuer-backend'),
  },
  plugins: [
    new NxAppWebpackPlugin({
      target: 'node',
      compiler: 'tsc',
      main: './src/main.ts',
      tsConfig: './tsconfig.app.json',
      assets: ['./src/assets'],
      optimization: false,
      outputHashing: 'none',
      generatePackageJson: true,
      transformers: [{ name: '@nestjs/swagger/plugin' }],
    }),
  ],
};

@ndcunningham but maybe this should be referenced in the documentation for nestjs

@Nazar-Brunarskyi
Copy link

Nazar-Brunarskyi commented May 14, 2024

@cre8 thanks!!
can you please share your project.json file for nestJS so I can have a look?

@cre8
Copy link
Author

cre8 commented May 14, 2024

@cre8 thanks!! can you please share your project.json file for nestJS so I can have a look?

Sure:

{
  "name": "issuer-backend",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/issuer-backend/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "init": {
      "executor": "nx:run-commands",
      "options": {
        "commands": [
          "cp apps/issuer-backend/.env.example apps/issuer-backend/.env"
        ]
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "issuer-backend:build"
      },
      "configurations": {
        "development": {
          "buildTarget": "issuer-backend:build:development"
        },
        "production": {
          "buildTarget": "issuer-backend:build:production"
        }
      }
    },
    "container": {
      "executor": "@nx-tools/nx-container:build",
      "dependsOn": ["build"],
      "options": {
        "engine": "docker",
        "push": true,
        "metadata": {
          "images": ["ghcr.io/cre8/wallet/issuer-backend"],
          "load": true,
          "tags": ["latest"]
        }
      }
    }
  }
}

You do not need to reference the webpack file anywhere, nx will use it automatically.

@Nazar-Brunarskyi
Copy link

@cre8 it was really helpful thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug
Projects
None yet
Development

No branches or pull requests

4 participants