published fresh until

pnpm monorepo: how do I rename a shared package?

Summary As of October 2026, rename the package manifest and every consumer dependency together, then rewrite exact package specifiers with a codemod and verify all consuming apps with typecheck and build; a folder rename alone is insufficient. Verify with pnpm -r build.

Not for choosing Turborepo, Nx or plain pnpm workspaces, see turborepo-nx-or-plain-pnpm-workspaces-for-a-ts-monorepo-2026; dead-code cleanup and non-rename legacy refactors, see case-clean-up-legacy-codebase-dead-code-renames-reviewable-prs-ast-grep

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Rename the workspace package and its consumer dependencies together, rewrite exact module specifiers, then typecheck and build every consuming app.

What changed

  • For this rename, the dependency graph changes as well as source text: pnpm workspace links and Turborepo package boundaries depend on package manifests, checked 2026-10-28.
  • Current Nx move options include --projectName, --newProjectName, --importPath and --updateImportPath, checked 2026-10-28. This is a project move generator, not a universal package-name codemod.

How to migrate

1. Record the old and new package name, all exported subpaths, every consuming app and the existing typecheck/build commands. Use rg -n --fixed-strings '@acme/old' apps packages plus a separate search of root manifests, build configuration and CI. These are example names to replace with your actual names. 2. Change the shared package's package.json name and consumer dependency keys in dependencies, devDependencies and peerDependencies. Preserve dependency ranges intentionally. Update self-imports and workspace aliases; pnpm supports aliases, so audit dependency values as well as keys. Regenerate the lockfile with the repository's pinned pnpm and review it. Do not hand-edit lockfile internals. 3. Pick one rewrite tool from the table below. For a package-only rename, keep its directory fixed to reduce the diff. If moving an Nx project too, inspect nx generate @nx/workspace:move <destination> --projectName=<old-project> --newProjectName=<new-project> --importPath=<new-package> using your installed generator's help before applying it. Review its edits before running another transform over them. 4. Match only s === oldName || s.startsWith(oldName + '/'); rewrite the matched prefix and preserve the suffix. Handle imports, type-only imports, re-exports, literal import(), literal require() and import('...') types. Flag computed imports for review; do not guess their runtime values. Do not rename @acme/old-extra. 5. With ts-morph, load each relevant tsconfig and list the included files first. Its import API provides getModuleSpecifierValue() and setModuleSpecifier(); the export API handles re-exports. A symbol's .rename() is a different operation. With jscodeshift, start with jscodeshift -t transforms/rename-package.cjs apps packages --extensions=ts,tsx --parser=tsx --dry --print --fail-on-error; this assumes you have written that transform. Run JS files separately with the appropriate parser. The runner flags are checked 2026-10-28. 6. Update TypeScript path aliases and config strings separately. Project references contain paths: change them when directories/config paths move, not merely because a package name changes. TypeScript build mode uses tsc -b to order referenced builds. 7. Install from the updated lockfile in a clean checkout, then run the real consumer checks. For repos that define these scripts, pnpm --filter '...@acme/new' run typecheck and pnpm --filter '...@acme/new' run build select the renamed package plus dependents; pnpm filtering explains the prefix ellipsis. On Turbo, use the configured task names, e.g. turbo run build check-types, and inspect the selected task graph. Run a full workspace check once because the graph itself changed.

Versions and licences

Repository manifest snapshots, checked 2026-10-28; these are not assertions about registry dist-tags. Keep your package manager and orchestrator pinned for the rename.

ToolSnapshot and licenceSource
ts-morph28.0.0; MIT; checked 2026-10-28Official manifest
jscodeshift17.4.0; MIT; checked 2026-10-28Official manifest

When to pick which

OptionPick whenNot for
Nx move generatorYou actually need to relocate an Nx project and update its import pathAssuming every arbitrary config string or runtime import is covered
ts-morphYou need TypeScript project context and controlled source editsAssuming one root tsconfig includes all workspace apps
jscodeshiftYou want a file-based TS/TSX transform with previewable outputSemantic symbol resolution or automatic manifest edits

What breaks

A consumer may still request the old name, a deep import may target a missing export, or a bundler alias may disagree with TypeScript. A successful editor rename does not prove runtime resolution. Moving directories can also break reference paths, asset paths and package exports.

What to test

Include fixtures for bare and subpath imports, type-only imports, re-exports, require, dynamic imports, unchanged relative paths and similarly prefixed packages. A second transform pass should make zero changes. Check declaration output, each app's production build, test/mocking aliases and a runtime smoke test through the public package entry points. Compare the inventory of consumers with the checks actually run.

Community evidence

  • In ts-morph issue 1653 (closed on 2026-11-21 by merged PR #1699), hoodmane reported different dependency-resolution results when loading files by tsconfig versus explicit globs. This supports enumerating loaded files, not assuming the project includes everything.
  • In issue 1667, jason-ha reports ESM-only export resolution trouble and proposes a workaround. It is a user report, not evidence that every current installation has that defect. Validate with your real compiler and bundler.

Pitfalls

Do not combine the rename with export redesign or dependency upgrades. Avoid a global text replacement across prose, generated output and unrelated identifiers. Preserve workspace: dependencies deliberately; an old package accidentally resolving from a registry can conceal an incomplete rename.

A prompt for your agent

Your training data may predate these APIs. Read the linked pnpm, Nx, ts-morph and jscodeshift official pages before editing; do not guess flags. Inventory consumers and all module-specifier forms. Propose a bounded, idempotent transform and fixtures, preserve subpaths, then update manifests and config. Show the diff, remaining old-name references and typecheck/build results for every consumer. Report computed imports that need a human decision.

Limits

This workflow was not executed on a monorepo. The issue reports illustrate failure modes, not independent successful end-to-end rename trials. Published external consumers need a separate release and compatibility plan; changing internal names does not migrate downstream repositories.

Started from a post by @hoodmane, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# pnpm monorepo: how do I rename a shared package?
Summary: As of October 2026, rename the package manifest and every consumer dependency together, then rewrite exact package specifiers with a codemod and verify all consuming apps with typecheck and build; a folder rename alone is insufficient. Verify with `pnpm -r build`.
Copy for agent
get the whatworks thread pnpm-monorepo-rename-shared-package-update-all-imports and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pnpm-monorepo-rename-shared-package-update-all-imports
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks