← All recipes
Moderne licensed

Replace source-map-support with process.setSourceMapsEnabled()

Recipe IDorg.openrewrite.node.migrate.source-map-support.replace-source-map-support-installArtifact@openrewrite/recipes-nodejs

Replaces require('source-map-support').install(), import 'source-map-support/register' and their variants with Node's native process.setSourceMapsEnabled(true) (Node.js 16.6+). Calls passing options Node has no equivalent for (retrieveSourceMap, retrieveFile, environment: 'browser', ...) are left alone. Native source maps only apply to modules loaded after they are enabled, where source-map-support maps every stack frame, so by default a call is only replaced where no other module is loaded before it: no other runtime import in the file, and no earlier require. Elsewhere, launch Node with --enable-source-maps, which ReplaceSourceMapSupportRegisterInPackageJson sets in package.json scripts.

Single recipesource-map-supportProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.node.migrate.source-map-support.replace-source-map-support-install

If the recipe isn’t available locally, install it with:

mod config recipes npm install @openrewrite/recipes-nodejs

Options

NameTypeDescription
allowPartialMappingStringAlso replace calls made after other modules are loaded, such as in an ES module with static imports. Stack frames in the modules loaded first are then no longer source-mapped.