• /
  • EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

Enable source maps support

Transpiled applications, such as those written in TypeScript or Babel, will show error stack traces that typically point to files, lines, and functions within the built files, rather than the source files.

If you enable source mapping in Node.js, you'll get more meaningful error traces that point to lines and functions within the source code.

How to enable source mapping

You can enable Node's source map support in the node command that starts your application:

bash
$
node --enable-source-maps -r newrelic ./dist/server.js

Example

An application run without source map support might display an error stack trace like this:

bash
Error: Failed to get all entries in model
at /dist/models/entries.js:41:23
... (multiple functions in New Relic Node agent js files)
at /dist/models/entries.js:39:35
at Generator.next (<anonymous>)

Note that the trace refers to the built files in /dist.

The same application with source map support enabled will instead reference the source code files:

bash
Error: Failed to get all entries in model
at <anonymous> (/src/models/entries.ts:28:13)
... (multiple functions in New Relic Node agent js files)
at <anonymous> (/src/models/entries.ts:26:19)
at Generator.next (<anonymous>)

This stack trace points to specific functions and line numbers within your source files, so you can find errors more easily.

You can observe this behavior by running our source maps example application, which makes it easy to compare error traces both with and without source maps enabled.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.