Skip to content

build!: drop the CommonJS build - #1362

Closed
dangreen wants to merge 2 commits into
docs/starlightfrom
build/esm-only
Closed

dangreen wants to merge 2 commits into
docs/starlightfrom
build/esm-only

Conversation

@dangreen

Copy link
Copy Markdown
Collaborator

Part 9 of the tooling stack. Based on #1361. Breaking: releases as v6.0.0.

What

  • ESM only. Vite builds only dist/index.js; dist/index.cjs is gone.

  • Exports map only in the published package.json, as the tree-shaking skill and nano_kit do: no main, no module.

    "exports": {
      ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
      "./package.json": "./package.json"
    }

    The condition is default, not import, so Node.js 20.19+ and 22.12+ can still require() the package (require of ESM). The top-level types stays for TypeScript's node10 resolution.

  • build clears dist first (as in nano_kit), so a stale index.cjs on a maintainer's machine cannot end up in the tarball.

  • Docs:

    • a Migration to v6 guide covering bundlers, Node.js, Jest and TypeScript;
    • the FAQ answer to "Cannot find module 'react-chartjs-2'", which used to say "upgrade to v5.1, where CommonJS was restored", is rewritten;
    • README links the guide;
    • AGENTS.md states the new policy.

The commit is build!: with a BREAKING CHANGE footer, so simple-release bumps the major version; keep the ! in the title when squash-merging.

Unchanged

API, props, types, peerDependencies, sideEffects: false, sizes (973 B for everything, 582 B for Chart, 99 B for an event helper).

Checked locally

  • pnpm test, pnpm test:size, pnpm prepublishOnly: package/dist contains only index.js and declarations.
  • The packed tarball installed into a scratch project with React 19 and Chart.js 4, on Node 26:
    • require('react-chartjs-2') and import('react-chartjs-2') both give the 12 exports;
    • TypeScript type-checks a consumer with moduleResolution bundler, nodenext, node10, and node16 in an ESM project. node16 in a CommonJS project reports TS1479, as the guide says; Chart.js types give the same error there;
    • esbuild bundles import { getElementAtEvent } into 212 B.
  • pnpm docs:build with the new guide in the sidebar.

Stack

  1. chore: agent skills and notes (chore: add agent skills lock and agent notes #1354)
  2. ci: Node.js 26, pnpm 12 and workflows (ci: update Node.js, pnpm and workflows #1355)
  3. build: Vite and Vitest (build: build and test with Vite #1356)
  4. chore: Storybook 10 (chore: update Storybook to 10 #1357)
  5. chore: sandboxes in the root workspace (chore: install the sandboxes from the root workspace #1358)
  6. chore: lint with oxlint (chore: lint with oxlint #1359)
  7. chore(deps): update dependencies (chore(deps): update dependencies #1360)
  8. docs: move the website to Starlight (docs: move the website to Starlight #1361)
  9. build!: drop the CommonJS build ← this PR

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.97%. Comparing base (f104440) to head (93df085).

Additional details and impacted files
@@               Coverage Diff               @@
##           docs/starlight    #1362   +/-   ##
===============================================
  Coverage           93.97%   93.97%           
===============================================
  Files                   3        3           
  Lines                  83       83           
  Branches               20       20           
===============================================
  Hits                   78       78           
  Misses                  3        3           
  Partials                2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dangreen
dangreen added this pull request to stack #1363 November 30, 2026 15:01
The package ships only its ES module build, with an exports map and no main or module fields, as tree-shakeable packages of the Trigen baseline do. The default condition lets Node.js 20.19+ and 22.12+ require() it. The build clears dist first, so an old index.cjs cannot be published.

BREAKING CHANGE: react-chartjs-2 is ESM only. Bundlers and Node.js 20.19+ or 22.12+ load it as before; older Node.js needs ESM code, and Jest needs to transform the package or run with ES modules support. See https://react-chartjs-2.js.org/docs/migration-to-v6/
The guide and the FAQ answer to "Cannot find module" explain how to load the ESM-only package in Node.js, Jest and TypeScript.
@dangreen

Copy link
Copy Markdown
Collaborator Author

Replaced by #1366: the CommonJS drop now goes before the Starlight website (#1367).

@dangreen dangreen closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant