Skip to content

fix(theme): support ESM import for v5 compatibility theme - #21759

Open
pratik-desgn wants to merge 1 commit into
apache:masterfrom
pratik-desgn:fix-21757-esm-v5-theme
Open

pratik-desgn wants to merge 1 commit into
apache:masterfrom
pratik-desgn:fix-21757-esm-v5-theme

Conversation

@pratik-desgn

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Adds an ESM-compatible v5 theme entry and conditional package exports so ESM imports register the theme on the application's ECharts module instance while existing CommonJS, AMD, and browser-global consumers keep using the current UMD entry.

Fixed issues

Details

Before: What was the problem?

The v5 theme entry is a UMD/CommonJS file that imports echarts/lib/echarts. When an application imports the ESM ECharts entry, Webpack can bundle a second ECharts module instance for the theme. The theme is then registered on that second instance and the chart continues using the ECharts 6 defaults.

The extensionless package export also has no concrete target.

After: How does it behave after the fixing?

The import condition for both echarts/theme/v5 and echarts/theme/v5.js now resolves to theme/v5.mjs, which registers through the package's ESM core entry. The require and default conditions remain on theme/v5.js, preserving the existing non-ESM entry points. The ESM file is marked as a side effect so bundlers retain the registration.

Document Info

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes.

Related test cases or examples to use the new APIs

Validated with the ECharts 6.1.0 package in Webpack 5.110.3:

  • The baseline bundle includes the legacy UMD theme wrapper; the patched bundle resolves the ESM entry.
  • Node ESM imports of both echarts/theme/v5 and echarts/theme/v5.js register the expected v5 palette.
  • TZ=UTC npm test -- --runInBand: 26 suites, 194 tests passed.
  • node --check theme/v5.mjs, node build/checkHeader.js, npm pack --dry-run --ignore-scripts, and git diff --check pass.

The normal npm run build:lib check is currently blocked by the checkout's existing TypeScript 4.4/dependency mismatch: installed newer @types/node and Babel declarations are rejected before this change is compiled.

Merging options

  • Please squash the commits into a single one when merging.

Other information

The commit includes the Apache-recommended Generated-by: OpenAI Codex provenance trailer.

@echarts-bot

echarts-bot Bot commented Sep 19, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant