Remove npm dependency

MSAL

Remove an npm dependency from package.json and regenerate the lock file natively, without executing the package manager. A pnpm workspace with cleanupUnusedCatalogs also loses the catalog entries no project references any more. If the dependency does not exist in any scope, the recipe is a no-op.

org.openrewrite.javascript.RemoveDependency

Required

The name of the npm package to remove (e.g., lodash, @types/node).

Optional

The dependency scope to remove from: dependencies, devDependencies, peerDependencies, optionalDependencies, or bundledDependencies. If not specified, removes from all scopes.

Keep the dependency in a package.json while a JavaScript or TypeScript source still imports a package matching one of these glob patterns, by import, export ... from, require() or import(). A pattern matches the package's name, so lodash covers lodash/fp. The package.json kept is the one Node resolves the dependency from for that source: the nearest one above it that declares the dependency. Imports are read as they stand before the recipes in a cycle edit them, so a migration that rewrites the imports and removes the dependency in one run causes another cycle, in which the dependency goes where no import is left. Leave unset to remove the dependency regardless of imports. Separate values with commas.

mod run . --recipe=org.openrewrite.javascript.RemoveDependency \ -P packageName=lodash

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.