A K
A K

Reputation: 183

Debug Nest.js application with Visual-studio-code in Nx monorepo

Trying to debug Nest.js application using vscode.

Auto Attach: always

Tried to find some relevant configuration, but could not find any, so I tried using the Next.js configuration suggested in this stackoverflow solution.

But it did not help.

So far, I could not make it through. I have not any relevant solution in the Nx docs which is pointing out this problem. If anyone has faced this issue earlier, would like to know how did you resole it?

Here is my tsconfig.json:

{
  "extends": "../../tsconfig.base.json",
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ],
  "compilerOptions": {
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true
  }
}

and here is my project.json setup:

{
  "name": "backend",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/backend/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "development",
      "options": {
        "target": "node",
        "compiler": "tsc",
        "outputPath": "dist/apps/backend",
        "main": "apps/backend/src/main.ts",
        "tsConfig": "apps/backend/tsconfig.app.json",
        "assets": ["apps/backend/src/assets"],
        "webpackConfig": "apps/backend/webpack.config.js"
      },
      "configurations": {
        "development": {}
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "backend:build",
        "inspect": true
      },
      "configurations": {
        "development": {
          "buildTarget": "backend:build:development",
          "inspect": true
        }
      }
    },
    "lint": {
      "executor": "@nx/eslint:lint",
      "outputs": ["{options.outputFile}"]
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "apps/backend/jest.config.ts"
      }
    }
  },
  "tags": []
}

Here is my launch.json file almost copied from Next.js launch.json configuration:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
          "name": "Debug Nest backend",
          "type": "node",
          "request": "launch",
          "runtimeExecutable": "npx",
          "runtimeArgs": ["nx", "run", "backend:serve"],
          "outputCapture": "std",
          "internalConsoleOptions": "openOnSessionStart",
          "console": "internalConsole",
          "env": {
            "NODE_OPTIONS": "--require=ts-node/register --require=tsconfig-paths/register",
            "TS_NODE_IGNORE": "false",
            "TS_NODE_PROJECT": "${workspaceFolder}/apps/backend/tsconfig.json"
          },
          "cwd": "${workspaceFolder}/apps/backend/"
        }
    ]
}

Also kept NODE_OPTIONS=--inspect in .env file.

At the end when I am trying to run the application in debug mode, I can the application is starting in debug console, but at the end the breakpoints are not activated in type-script files, but the breakpoints are getting activated inside dist/apps/backend/main.js

No matter, whatever the configuration I make, the application is always building the code from ts to dist/apps/backend/main.js file and starting from dist/apps/backend/main.js only.

Upvotes: 0

Views: 58

Answers (0)

Related Questions