echarts: [Bug] package.json is missing a package "type": "module" description
Version
5.3.1
Link to Minimal Reproduction
No response
Steps to Reproduce
Create app with nuxt bridge Build that app using nuxi build preview this app using nuxi preview
Current Behavior
Node throws error while trying import package as cjs module
Expected Behavior
Node import package as esm module
Environment
- OS: Windows 11
- Browser: Chrome 97
- Framework: Nuxt 2 Bridge
Any additional comments?
After building the application with nuxt bridge and running the application, Node tryes to import echarts and zrender as CJS modules, but there are ESM, as I can see. After I specified “type”: “module” in both packages, the problem has been solved.
Please specify module type in package.json
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 16 (1 by maintainers)
This is a bug.
import * as echarts from 'echarts/core'leads tobecause the content of
.jsfiles is determined by the value fortypein the closest package.json.A proper fix for this requires a major release, as it affects the way current users import (or require) echarts. If you want to continue supporting cjs you need an exports map. A guide for releasing dual packages can be found here https://antfu.me/posts/publish-esm-and-cjs
Alternatively an
echarts-esmpackage could be forked/released that no longer supports cjsOne possible workaround to fix this within 5.x would be to add files with explicit
.mjsextension for all current js files that are imported anywhere or used as entry points.ps. zrender has a similar issue.
Hi, any updates for the issue ? I’m also stuck and got this error when i tried to compil my app.
import * as echarts from 'echarts'with echarts 5.4.1Cannot make echarts working with vitest because of this issue. Please considering fixing
package.jsonaccording to this guide: https://github.com/sheremet-va/dual-packagingSame problem using Node, Vite and echarts 5.4.2.
Bump, this feature is really important as Vite-based framework sometimes does not work with this format. @100pah sorry for mentioning, but may you ship this at 5,5 or nearest milestones. https://github.com/sheremet-va/dual-packaging requires only does not require a lot
Same issue for me.
Nuxt 3.8.2 & latest echarts.
similar issue here in fact
import * as echarts from "echarts"does work, butimport * as echarts from "echarts/core"doesn’t. Error:export * from './lib/export/core.js';Having this only as ESM makes it unusable following the “minimal bundle” instructions when using CRA/using Jest. https://github.com/facebook/create-react-app/issues/12063
It is impossible to run tests, but works fine while building or developing … makes the “minimal bundle” with TypeScripts unusable.
Relating other issues: https://github.com/apache/echarts/issues/14864 https://github.com/apache/echarts/issues/14965
Fixed by #19513
@Sujith1799 not yet, the only workaround I know is to not import the page when testing, as suggested here: https://github.com/facebook/create-react-app/issues/12063#issuecomment-1215725669
Something like this:
This does not “make it testable”, it just makes jest jump over the problematic stuff (until its fixed).
Just remember as this uses the lazy-loading stuff, to wrap a
<Suspense>around it: