Repository navigation
fix: stop tsc clobbering the cjs build and ship real ESM from the module entry - #131
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The changes align the build outputs with the package entry points; only a minor, non-blocking log message mismatch was found.
Pull request overview
Fixes long-standing packaging issues so the published artifacts match their declared entry points (CJS for main, real ESM for module/next) without TypeScript overwriting Babel output.
Changes:
- Prevent
tscfrom overwriting the Babel-generated CJS build by enablingemitDeclarationOnlyintsconfig.publish.json. - Stop emitting
tsbuildinfointo the publish output by switching fromtsc --buildtotsc -p. - Ensure ESM outputs stay ESM by setting
modules: falsefor theesBabel env and adding per-folder"type":"module"markers fordist/esanddist/next.
File summaries
| File | Description |
|---|---|
tsconfig.publish.json |
Emits declarations only to avoid clobbering Babel’s JS output in dist/. |
.scripts/user/prepublish.sh |
Uses tsc -p for declaration emission (non-build mode). |
.scripts/prepublish.sh |
Adds ESM marker package.json files to dist/es and dist/next. |
.babelrc |
Preserves ESM syntax for the es build via modules: false. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Declarations go to dist/, not dist/types — package.json points `types` at dist/index.d.ts. Flagged in review on kindred #131. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
6d47e6d to
ce243eb
Compare
Declarations go to dist/, not dist/types — package.json points `types` at dist/index.d.ts. Flagged in review on [react-aspect-ratio#131](#131). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ce243eb to
4a9b3ba
Compare
Declarations go to dist/, not dist/types — package.json points `types` at dist/index.d.ts. Flagged in review on [react-aspect-ratio#131](#131). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
4a9b3ba to
b146bc1
Compare
…ule entry
Two long-standing packaging bugs, both predating v2.
tsc shares dist/ with babel and ran second, so `tsc --build tsconfig.publish.json`
overwrote dist/index.js — babel's ES5 CommonJS output — with its own ESNext emit.
The published `main` was never the babel build. tsconfig.publish.json now sets
emitDeclarationOnly, and the plain -p form replaces --build so no tsbuildinfo
lands in dist/ either.
The `es` babel env set targets.esmodules but not modules:false, so preset-env
still downlevelled import/export to CommonJS and the declared `module` entry
shipped require(). Fixed, and the es/ and next/ directories now get a
{"type":"module"} marker so Node reads them as ESM rather than reparsing.
dist/index.js grows 437B -> 694B gzipped: it is now the ES5 build it always
claimed to be, not the ESNext emit that was overwriting it. Still well under
the 2KB budget.
Verified by rendering both entry points through react-dom/server — identical
markup from main and module.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Declarations go to dist/, not dist/types — package.json points `types` at dist/index.d.ts. Flagged in review on [react-aspect-ratio#131](#131). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
b146bc1 to
b6299da
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The publish build script can continue after a failed build step and still exit successfully, which risks publishing an incomplete or incorrect dist/.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
Stacked on react-aspect-ratio#129 (which is itself stacked on react-aspect-ratio#128) — base is
v2-pnpm. Merge order: 128 → 129 → this.Fixes the two pre-existing packaging bugs flagged in #129. Both predate v2 and affect what
1.xpublished too.1.
tscwas overwriting the CommonJS build.scripts/prepublish.shruns babel intodist/, then.scripts/user/prepublish.shrunstsc --build tsconfig.publish.jsonfor the.d.tsfiles. That tsconfig inheritsoutDir: dist,noEmit: falseandtarget: ESNextfrom the base config — so tsc emitted.jsas well and, running second, replaced babel's ES5 CommonJSdist/index.jswith its own ESNext output. The publishedmainhas never been the babel build the script claims to produce.tsconfig.publish.jsonnow setsemitDeclarationOnly: true. Switched--build→ plain-pat the same time, which also stopstsconfig.publish.tsbuildinfobeing emitted into the publisheddist/.2. The
moduleentry point shipped CommonJSThe
esenv in.babelrcsettargets.esmodulesbut notmodules: false, so preset-env still downlevelledimport/export.dist/es/index.js— the filemodulepoints at — shippedrequire()andexports.__esModule, defeating tree-shaking for every bundler that resolved it.Added
modules: false. Bothes/andnext/now also get a{"type":"module"}marker file, since they are ESM with a.jsextension in a package with no top-level"type"— without it Node reparses them (MODULE_TYPELESS_PACKAGE_JSON) and would treat them as CommonJS.Size
dist/index.jsgoes 437B → 694B gzipped. That is the fix working, not a regression: it is now the ES5 build it always claimed to be, rather than the ESNext emit that had been overwriting it. Still comfortably under the 2KB budget.Verification
mainis CJS,module/nextare ESM (export function/export default),umdis UMD.react-dom/server:require('dist/index.js')andimport 'dist/es/index.js'produce identical markup (<div class="react-aspect-ratio-placeholder" style="--aspect-ratio:(0.75)">y</div>), with both default and named exports present on each.MODULE_TYPELESS_PACKAGE_JSONwarning after the marker files.pnpm run test:ci6/6,tsc --noEmitclean,bundlesize4/4.🤖 Generated with Claude Code