build(packages): emit ESM type marker for publish#8
Merged
Conversation
- Add scripts/write-esm-package-json.js to write dist/esm/package.json
with {"type":"module"} as a postbuild step. Required so bundlers
(webpack, esbuild, vite, rollup) and older Node parse the ESM build
as modules rather than CJS.
- Drop "source": "./src/index.ts" from each package's exports map.
Source files are not shipped in dist/, so this condition pointed at
nothing in the published tarball.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scripts/write-esm-package-json.jsas a shared postbuild step that writesdist/esm/package.jsonwith{"type":"module"}. Without this marker, bundlers (webpack, esbuild, vite, rollup) and older Node versions parsedist/esm/*.jsas CommonJS and error on theexportsyntax emitted bytsc."source": "./src/index.ts"from each package's exports map —src/is not shipped in the published tarball, so this condition pointed at a path that doesn't exist for consumers.Why this is the minimum needed to publish
The published shape is dual-CJS+ESM (
index.js+esm/index.js). Node and bundlers determine how to parse.jsfiles via the closestpackage.json's"type"field. Without a marker insidedist/esm/, the ESM build inherits the package root's default ("commonjs") and fails wherever syntax detection isn't available.Verification
Decisive pack-and-import matrix run against
@agentic-kit/anthropic(leaf package, no workspace deps):--no-experimental-detect-module)ERR_REQUIRE_CYCLE_MODULErequire)Test 2 vs Test 4 isolates the marker as the cause: same Node, same tarball shape minus one file, opposite outcomes.
Test plan
pnpm clean && pnpm build— all 6 packages emitdist/esm/package.jsonwith{"type":"module"}pnpm test— 99 tests pass across 6 packages--experimental-detect-module)require()from a CJS consumerlerna publishdry-run sanity check before the first real publishOut of scope
jest.environment.jseslint-disable directive (lives in a separate branch). CI doesn't gate on lint, so this PR is independently mergeable.engines.nodefloor — keeping the marker means we don't need to commit to a Node version yet.🤖 Generated with Claude Code