Skip to content

build!: drop the CommonJS build - #1366

Merged
dangreen merged 2 commits into
masterfrom
build/drop-commonjs
Nov 30, 2026
Merged

dangreen merged 2 commits into
masterfrom
build/drop-commonjs

Conversation

@dangreen

@dangreen dangreen commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Part 8 of the tooling stack. Based on master (#1354–#1360 are merged). Breaking: releases as v6.0.0.

Replaces #1362: the CommonJS drop now goes before the Starlight website, so the docs here are for the current Docusaurus website and the Starlight PR moves them over.

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.
  • The Docusaurus website build (pnpm build in website): /docs/migration-to-v6/ is generated and linked in the docs sidebar, and the FAQ answer is updated.

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. build!: drop the CommonJS build ← this PR
  9. docs: move the website to Starlight (docs: move the website to Starlight #1367)

🤖 Generated with Claude Code

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.
@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 (8f33494) to head (5bf3e8d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1366   +/-   ##
=======================================
  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 marked this pull request as ready for review November 30, 2026 16:03
@dangreen
dangreen merged commit 811aaf6 into master Nov 30, 2026
11 checks passed
@dangreen
dangreen deleted the build/drop-commonjs branch November 30, 2026 16:04
@github-actions github-actions Bot mentioned this pull request Nov 30, 2026
dangreen added a commit that referenced this pull request Nov 30, 2026
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.

The migration guide to v6 and the FAQ answer to "Cannot find module" explain how to load the ESM-only package in Node.js, Jest and TypeScript.

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/
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