ComfyChloe opened a new issue, #21778:
URL: https://github.com/apache/echarts/issues/21778
## Summary
echarts declares `"types": "index.d.ts"` in its package manifest, but
`index.d.ts` is authored in CommonJS style and ends with `export = echarts`.
TypeScript rejects that when the consuming project targets ECMAScript modules,
so any modern ESM project with `skipLibCheck: false` fails to typecheck.
## Affected file
```ts
// node_modules/echarts/index.d.ts (lines 21-23)
import * as echarts from './types/dist/echarts';
// Export for UMD module.
export as namespace echarts;
export = echarts; // <-- TS1203 under `module: ESNext`
```
## Package manifest (5.6.0)
```json
{
"main": "dist/echarts.js",
"module": "index.js",
"types": "index.d.ts",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js",
"require": "./dist/echarts.js"
}
}
}
```
Both the legacy `types` field and the `exports["."].types` condition resolve
to the CommonJS-authored `index.d.ts`. The ESM-friendly declarations already
exist at `./types/dist/echarts.d.ts` and are exported (e.g.
`./types/dist/echarts`), but the default entrypoint does not point at them.
## Reproduction
```jsonc
// tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2023", "DOM"],
"strict": true,
"skipLibCheck": false,
"noEmit": true
}
}
```
```ts
import type { EChartsOption } from 'echarts';
export const o: EChartsOption = {};
```
```
error TS1203: Export assignment cannot be used when targeting ECMAScript
modules.
Consider using 'export default' or another module format instead.
at node_modules/echarts/index.d.ts:23:1
```
This error appears regardless of `exactOptionalPropertyTypes`; it is purely
the `module: ESNext` + `export =` combination.
## Relation to previously closed issues
ESM compatibility has been reported and closed before — #20554
("Compatibility with ESM") and #21250 ("Cannot use ESM imports in modern
TypeScript project"). Both were closed, yet the default `types` entry still
resolves to a CommonJS declaration file in 5.6.0, so this looks like a
regression rather than a new problem.
## Suggested fix
Point the type entrypoints at the ESM declaration file, e.g. ship an
`index.d.mts` (or make `index.d.ts` ESM-authored) and have `exports["."]`
select it:
```json
{
"exports": {
".": {
"import": { "types": "./index.d.mts", "default": "./index.js" },
"require": { "types": "./index.d.ts", "default": "./dist/echarts.js" }
}
}
}
```
## Environment
- echarts 5.6.0
- TypeScript 5.9.3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]