← All recipes
Moderne licensed

Change import

Recipe IDorg.openrewrite.javascript.change-importArtifact@openrewrite/rewrite

Changes an import from one module/member to another, updating all type attributions.

Single recipeMSAL

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.javascript.change-import --recipe-option "oldModule=react-dom/test-utils" --recipe-option "oldMember=act" --recipe-option "newModule=react"

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

mod config recipes npm install @openrewrite/rewrite

Options

NameTypeDescription
oldModulerequiredThe module to change imports from
e.g. react-dom/test-utils
oldMemberrequiredThe member to change (or 'default' for default imports, '*' for namespace imports)
e.g. act
newModulerequiredThe module to change imports to
e.g. react
newMemberThe new member name. If not specified, keeps the same member name.
e.g. act
newAliasThe local name to bind the new member under. Defaults to the alias the import already had, or to the new member name where it had none.
e.g. act