echarts icon indicating copy to clipboard operation
echarts copied to clipboard

[Bug] Cannot use ESM imports in modern TypeScript project

Open nwalters512 opened this issue 5 months ago • 2 comments

Version

6.0.0

Link to Minimal Reproduction

https://github.com/nwalters512/echarts-typescript-esm-repro

Steps to Reproduce

Install dependencies:

yarn install

Try to build the project:

yarn build

Current Behavior

Observe that there are a number of TypeScript errors:

node_modules/echarts/charts.d.ts:20:15 - error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

20 export * from './types/dist/charts';
                 ~~~~~~~~~~~~~~~~~~~~~

node_modules/echarts/index.d.ts:20:26 - error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

20 import * as echarts from './types/dist/echarts';
                            ~~~~~~~~~~~~~~~~~~~~~~

node_modules/echarts/index.d.ts:23:1 - error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.

23 export = echarts;
   ~~~~~~~~~~~~~~~~~

src/named-import.ts:1:10 - error TS2305: Module '"echarts/charts"' has no exported member 'BarChart'.

1 import { BarChart } from 'echarts/charts';
           ~~~~~~~~

src/star-import.ts:1:26 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.

1 import * as echarts from 'echarts';
                           ~~~~~~~~~


Found 5 errors in 4 files.

Expected Behavior

Given that I've followed the instructions on https://echarts.apache.org/handbook/en/basics/import/, I'd expect these imports to just work.

Environment

- OS: macOS 15.6.1
- Browser: N/A
- Framework: N/A

Any additional comments?

https://arethetypeswrong.github.io/?p=echarts%406.0.0 indicates that there are a variety of issues with the TypeScript types.

I noted that https://github.com/apache/echarts/issues/20554 seemingly describes a similar issue, but doesn't include a minimal reproduction and also was specifically for v5.X. I couldn't find an issue with a minimal reproduction that was for 6.X.

nwalters512 avatar Sep 08 '25 19:09 nwalters512

I have the same issue.

first install:

npm install echarts

then import to use:

import * as echarts from 'echarts';

Error:

error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.

However, even with that flag it doesn't work

brianlagunas avatar Nov 24 '25 05:11 brianlagunas

I'm also getting this, same reproduction steps as @brianlagunas

MattElcock avatar Dec 05 '25 10:12 MattElcock

Fixed #21411

100pah avatar Dec 18 '25 17:12 100pah