2

Trying to debug nodejs typescript files while running firebase emulators. However, breakpoints are unbounded so even though the debugger starts and attaches to port 9229 breakpoints are not getting hit. Below are my vscode settings and tsconfig, etc.

Anyone running firebase emulators run into this issue trying to debug in vscode? I'm running VS Code Version: 1.75.0.

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": false,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "noImplicitAny": false,
    "strictNullChecks": false,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  },
  "compileOnSave": true,
  "include": ["src", "index.ts"]
}

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Debug",
      "port": 9229,
      "trace": true
    }
  ]
}

package.json

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "build:watch": "tsc --watch",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "dev": "cd ~/AndroidStudioProjects/order_fulfillment && firebase emulators:start --import=saved-data --export-on-exit && tsc --watch",
    "debug": "cd ~/AndroidStudioProjects/order_fulfillment && firebase emulators:start --import=saved-data --export-on-exit --inspect-functions && tsc --watch",
    "deploy": "cd functions && npm ci && npm run build && cd .. && firebase deploy --only hosting",
    "web": "cd ~/AndroidStudioProjects/order_fulfillment && flutter run -d chrome --web-renderer canvaskit --web-hostname localhost --web-port 45887",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@elastic/elasticsearch": "^8.2.1",
    "@google-cloud/pubsub": "^2.15.1",
    "@google-cloud/secret-manager": "^3.7.1",
    "@sendgrid/mail": "^7.6.0",
    "@shopify/shopify-api": "^5.0.1",
    "aws-sdk": "^2.1231.0",
    "axios": "^0.27.2",
    "body-parser": "^1.19.2",
    "cors": "^2.8.5",
    "csvtojson": "^2.0.10",
    "eslint": "^8.23.0",
    "express": "^4.17.2",
    "firebase-admin": "^11.0.1",
    "firebase-functions": "^4.2.1",
    "html-pdf-node": "^1.0.8",
    "luxon": "^1.27.0",
    "node-fetch": "^2.6.7",
    "pdf-merger-js": "^4.1.0",
    "qrcode": "^1.5.1",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@types/download": "^8.0.1",
    "@types/html-pdf": "^3.0.0",
    "@types/luxon": "^1.27.0",
    "@types/mime-types": "^2.1.1",
    "@types/node-fetch": "^2.6.1",
    "@types/pdfkit": "^0.12.6",
    "@types/qrcode": "^1.5.0",
    "@types/request": "^2.48.7",
    "@typescript-eslint/eslint-plugin": "^5.12.0",
    "@typescript-eslint/parser": "^5.12.0",
    "concurrently": "^7.4.0",
    "eslint-config-google": "^0.14.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-prettier": "^4.2.1",
    "firebase-functions-test": "^0.2.0",
    "node": "^18.8.0",
    "prettier": "^2.7.1",
    "typescript": "^4.5.4"
  },
  "private": true,
  "version": "1.0.0",
  "author": "",
  "license": "ISC",
  "description": ""
}

I added trace to launch.json and opened the vscode debug file at https://microsoft.github.io/vscode-pwa-analyzer/index.html and this is an example of what the logs show for the unbounded breakpoint.

VS Code Debug Log Viewer Example

As you can see in screenshot, TS is getting compiled correctly to the outDir so there should not be any issues with mapping.

Screenshot demonstrating tsc is building to lib directory.

I have reached out to vscode support, but they are suggesting it is not vscode and some kind of issue with firebase setup? However, all my emulators are running just fine and I am able to do everything, but set a breakpoint and debug.

cDillanb
  • 21
  • 3

1 Answers1

1

I think you need to set the outFiles attribute in your launch.json file. See the VS Code docs on TypeScript debugging > Mapping the output location:

If generated (transpiled) JavaScript files do not live next to their source, you can help the VS Code debugger locate them by setting the outFiles attribute in the launch configuration. Whenever you set a breakpoint in the original source, VS Code tries to find the generated source by searching the files specified by glob patterns in outFiles.

I'm not sure exactly what value you need to use for the setting, but I suspect its something based on the value of your outDir setting in your tsconfig.json, perhaps with a trailing /**/*.js (or perhaps not). If this works for you, suggest an edit to this answer with the exact value that you got to work.

starball
  • 20,030
  • 7
  • 43
  • 238
  • Have you happened to see it when the file does exist? I'm seeing this error message however the file path vscode provides saying it couldn't find, I can copy and paste straight from vscode into a terminal and it prints it out just fine. The file very much exists and is exactly where vscode tells me it is looking – Grant Curell Aug 14 '23 at 18:52