dist-build-migration

Migrates Nx packages to local dist builds with nodenext module resolution and exports maps.

29.3k|3.0k|Updated Aug 11, 2017
One-click install
npx skills add https://github.com/nrwl/nx --skill dist-build-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dist-build-migration
Source: https://github.com/nrwl/nx/tree/main/.claude/skills/dist-build-migration
Command: npx skills add https://github.com/nrwl/nx --skill dist-build-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating an Nx monorepo package from building to a workspace-root dist/packages/<name> directory to building locally into packages/<name>/dist/ involves dozens of coordinated changes across tsconfig, package.json, project.json, eslint, release scripts, and consumer imports. Missing any step causes publish failures, sandbox violations, or runtime module-resolution crashes.

Core Features & Use Cases

  • Build layout migration: Rewrites tsconfig.lib.json to nodenext module resolution with local dist output, and updates package.json with an exports map using the @nx/nx-source condition plus typesVersions fallbacks.
  • Release and publish alignment: Configures project.json release settings (preserveLocalDependencyProtocols, manifestRootsToUpdate), files fields, and scripts/nx-release.ts so versioning and publishing work from the source package root.
  • Consumer import codemods: Updates @nx/<name>/src/* imports across the workspace, optionally locking down the ./src/* wildcard behind a curated ./internal entry point with a shipped migration.
  • Use Case: You maintain the Nx repo and need to migrate the @nx/js package to the local-dist build pattern already used by nx and devkit, including fixing require('../../package.json') fragility and ensurePackage + dynamic import() breakage under nodenext.

Quick Start

Migrate the @nx/js package to the local dist build pattern and update all dependent configuration and imports.

Frequently Asked Questions about dist-build-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate an Nx package to build into a local dist directory?

Update tsconfig.lib.json to use outDir "dist" with module and moduleResolution set to nodenext, then point package.json main and types at ./dist files and add an exports map. Also update project.json release settings, eslint ignores, and the files field.

What is the @nx/nx-source condition in package.json exports?

The @nx/nx-source condition is a custom exports condition used for source-level resolution within the Nx workspace, so other packages import from TypeScript source rather than built dist output. Each export entry pairs it with types and default conditions pointing at dist files.

Why does require('../../package.json') break after migrating to local dist builds?

After migration the built file lives at packages/<name>/dist/src/..., so the relative path resolves to packages/<name>/dist/package.json, which does not exist. Replace it with require(join('@nx/<name>', 'package.json')) so Node resolves it via node_modules.

Why does ensurePackage with await import fail under nodenext module resolution?

Under nodenext, dynamic import() is a true ESM import that ignores Module._initPaths, where ensurePackage registers its temporary install. Replace the dynamic import with a synchronous require() typed via typeof import() so resolution honors the temp install path.

When should I lock down the ./src/* exports wildcard to an ./internal entry point?

Lock it down in the same PR when internal subpath imports are manageable and no unmigrated workspace:* dependents rely on old paths. Defer when the import inventory is huge or other packages' dist output still resolves against the old published version.