#Source Maps Not Mapping to Original TypeScript Files in NestJS Project

5 messages · Page 1 of 1 (latest)

inner swan
#

Overview: I’m using Sentry with a NestJS (Node.js) backend to monitor errors and performance. I’ve set up source maps to map my compiled JavaScript files (dist/.js) back to my original TypeScript files (src/.ts). I've tried to use bash npx @sentry/wizard@latest -i sourcemaps but it didn't helped at all. I’m using sentry-cli to inject Debug IDs and upload source maps, but the stack traces and profiles in Sentry are not mapping to my src/*.ts files. Instead, I see "No Instrumentation" warnings in traces, and profiles show generic function names like f0, f1, etc., instead of my actual code.

Project Details:

  • Organization: bombonchik
  • Project: next-nonce
  • Release: my-nest-app@0.0.1
  • Sample Trace ID: 78547ec7f4f (from the DELETE /v1/users/me trace)
  • Environment: Production
  • Node.js Version: v20.17.0
  • Sentry SDK: @sentry/nestjs (version not specified, but I can provide if needed)
  • Profiling: Enabled with @sentry/profiling-node

Build and Upload Process:

  1. I build my NestJS project using:
    yarn build
    My package.json script is:
    "sentry:sourcemaps": "sentry-cli sourcemaps inject --org bombonchik --project next-nonce dist && sentry-cli sourcemaps upload --org bombonchik --project next-nonce --url-prefix '/dist' --release=my-nest-app@0.0.1 dist"
faint quartzBOT
#

Hi @inner swan. I'm happy to dig into this for you! I'll check my internal sources for answers to your question! :wave:

#

Based on the information in your question, I can see you're having issues with source maps not properly mapping to your original TypeScript files in your NestJS project. This is a common issue with TypeScript projects, and there are a few key things to check.

The Source Map Support Issue

The most likely cause of your problem is that you're using NestJS's built-in source map support. As mentioned in the knowledge sources, NestJS CLI injects source-map-support by default, which can interfere with Sentry's source map functionality.

According to users who had the same issue:

By default, it had source-map-support in its dev dependencies list, which I completely forgot. The first step to make it work is uninstalling that sneaky little package.

yarn remove source-map-support

JavaScript SDK GitHub Issue

Running Your App Correctly

Another critical factor is how you start your application in production:

Next, you need to make sure that your app is not starting in production environment using nest start, because it injects source maps by itself. In production, I run my app with bare Node anyway and it took me far too long to realize I was using nest start in my "local production" setup.

Try running your app with:

node dist/main.js

Instead of using nest start or similar NestJS commands.

Proper Source Map Configuration

Make sure your TypeScript configuration is correct. Your tsconfig.json should include:

{
  "compilerOptions": {
    "sourceMap": true,
    "inlineSources": true,
    "sourceRoot": "/"
  }
}

TypeScript Source Maps Guide

Rewriting Frames

#

You might need to use the rewriteFrames integration to ensure paths are correctly mapped:

Sentry.init({
  // other config
  integrations: [
    rewriteFramesIntegration({
      root: process.cwd(),
    }),
  ],
  // other config
})

This will add an app:/// prefix to your paths and remove the root directory, which helps Sentry correctly map the stack traces.

Verifying Debug IDs

Check that your JavaScript files contain debug ID snippets and that your events contain a debug_meta field in the payload. If your events don't have a debug_meta field, it means something is transforming your stack traces before they reach Sentry.

You can verify this by looking at the raw JSON of an event in Sentry and searching for the debug_meta field.

Source Map Upload Command

Your current upload command looks good, but make sure you're running the inject command before uploading:

sentry-cli sourcemaps inject --org bombonchik --project next-nonce dist && 
sentry-cli sourcemaps upload --org bombonchik --project next-nonce --url-prefix '/dist' --release=my-nest-app@0.0.1 dist

Summary

To fix your issue:

  1. Remove source-map-support from your dependencies
  2. Run your app with node dist/main.js instead of nest start
  3. Ensure your TypeScript config has the correct source map settings
  4. Use the rewriteFrames integration
  5. Verify that debug IDs are being injected and included in your events

These steps have helped others with the exact same issue in NestJS projects.

Hope this helps! Let me know if you need any clarification.

Lima: 5

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@inner swan Our robots are still learning and improving, please let us know if this response was correct by reacting below.