Skip to content

fix: publish the type declarations and fix the ESM export path - #968

Merged
kurkle merged 1 commit into
chartjs:masterfrom
kurkle:fix-package-declarations
Sep 16, 2026
Merged

kurkle merged 1 commit into
chartjs:masterfrom
kurkle:fix-package-declarations

Conversation

@kurkle

@kurkle kurkle commented Sep 16, 2026

Copy link
Copy Markdown
Member

Since the TypeScript conversion in #907 the package has shipped no types at all, and could not be imported from ESM. Both are still unreleased: v2.2.0 predates that commit.

"types" pointed at dist/index.d.ts, but tsc --emitDeclarationOnly writes to dist/src/, because rootDir has to stay at the repo root for src/plugin.ts to import the version out of package.json. The "dist/*.d.ts" entry in "files" does not match a subdirectory, so nothing was packed. Point both at dist/src/ instead.

"exports.import" asked for dist/chartjs-plugin-zoom-esm.js. Rollup writes chartjs-plugin-zoom.esm.js, so import 'chartjs-plugin-zoom' failed with ERR_MODULE_NOT_FOUND.

The specs live beside the sources, so declaration emit moves to tsconfig.build.json, which excludes them; tsconfig.json still includes them and npm run typecheck keeps covering them.

Verified by installing the packed tarball into a throwaway project: tsc resolves the types and import() returns the plugin, both of which fail with the tarball built from master.

This publishes the module layout as tsc emits it, so core, gestures, handlers, state and the rest land in the tarball as separate declarations. A follow-up rolls them into a single dist/index.d.ts; keeping that separate leaves this commit to the two outright bugs.

require('chartjs-plugin-zoom') still returns {} either way, because "type": "module" makes node read the UMD bundle as ESM. That needs a separate CJS output and is left alone here.

Since the TypeScript conversion in chartjs#907 the package has shipped no types at
all, and could not be imported from ESM. Both are still unreleased: v2.2.0
predates that commit.

"types" pointed at dist/index.d.ts, but `tsc --emitDeclarationOnly` writes to
dist/src/, because rootDir has to stay at the repo root for src/plugin.ts to
import the version out of package.json. The "dist/*.d.ts" entry in "files"
does not match a subdirectory, so nothing was packed. Point both at dist/src/
instead.

"exports.import" asked for dist/chartjs-plugin-zoom-esm.js. Rollup writes
chartjs-plugin-zoom.esm.js, so `import 'chartjs-plugin-zoom'` failed with
ERR_MODULE_NOT_FOUND.

The specs live beside the sources, so declaration emit moves to
tsconfig.build.json, which excludes them; tsconfig.json still includes them
and `npm run typecheck` keeps covering them.

Verified by installing the packed tarball into a throwaway project: `tsc`
resolves the types and `import()` returns the plugin, both of which fail with
the tarball built from master.

This publishes the module layout as tsc emits it, so core, gestures, handlers,
state and the rest land in the tarball as separate declarations. A follow-up
rolls them into a single dist/index.d.ts; keeping that separate leaves this
commit to the two outright bugs.

`require('chartjs-plugin-zoom')` still returns {} either way, because "type":
"module" makes node read the UMD bundle as ESM. That needs a separate CJS
output and is left alone here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kurkle kurkle added the types label Sep 16, 2026
@kurkle
kurkle merged commit 85a2c8c into chartjs:master Sep 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant