source-map-support
raw JSON → 0.5.21 verified Fri May 01 auth: no javascript
Provides source map support for stack traces in Node.js and browsers via the V8 stack trace API. Current stable version: 0.5.21. Uses the Mozilla source-map module to replace paths and line numbers of source-mapped files with originals. Key differentiator: works with any compile-to-JS language, supports both CLI (-r) and programmatic usage, and includes browser support via bundled script. Maintained by Evan Wallace, releases are infrequent but stable.
Common errors
error TypeError: Cannot read properties of undefined (reading 'name') ↓
cause Bug in version <0.5.16 when a stack frame lacks function name
fix
Update source-map-support to >=0.5.16
error ReferenceError: window is not defined ↓
cause Trying to use browser-source-map-support.js in Node.js environment
fix
Use the Node-specific module (require('source-map-support')) instead of browser version
error Error: source-map-support/register must be required before any other modules ↓
cause The register module was required after other code has executed
fix
Add --require source-map-support/register as the first CLI argument or require it at the very top of the entry file
Warnings
breaking Cannot read property 'name' of undefined ↓
fix Upgrade to >=0.5.16
gotcha Module does not support source maps in stack traces when errors are thrown before install() is called ↓
fix Call install() at the very top of your entry file, before any other code
gotcha Only works with V8 engine (Node.js, Chrome) - not with other JavaScript engines ↓
fix Not applicable; this is a design limitation
Install
npm install source-map-support yarn add source-map-support pnpm add source-map-support Imports
- sourceMapSupport wrong
const sourceMapSupport = require('source-map-support').defaultcorrectimport sourceMapSupport from 'source-map-support' - install wrong
const install = require('source-map-support/install')correctrequire('source-map-support').install() - register wrong
require('source-map-support/register') in ESMcorrectimport 'source-map-support/register'
Quickstart
// Install: npm install source-map-support
// In your compiled file:
require('source-map-support').install();
// Or via CLI:
// node -r source-map-support/register compiled.js
// Example with options:
require('source-map-support').install({
handleUncaughtExceptions: false,
environment: 'node'
});
// Browser usage:
// <script src="browser-source-map-support.js"></script>
// <script>sourceMapSupport.install();</script>
// For TypeScript (ESM):
import sourceMapSupport from 'source-map-support';
sourceMapSupport.install();