Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a valid ESM entry #627

Open
1 task done
kingyue737 opened this issue Jun 9, 2022 · 10 comments
Open
1 task done

Need a valid ESM entry #627

kingyue737 opened this issue Jun 9, 2022 · 10 comments

Comments

@kingyue737
Copy link
Contributor

kingyue737 commented Jun 9, 2022

Confirmation

  • I can confirm this problem is not reproducible with ECharts itself.

How are you introducing Vue-ECharts into your project?

ES Module imports

Versions

Legend: production dependency, optional only, dev only

vue-project@0.0.0 D:\webprojects\vue2-echarts

dependencies:
echarts 5.3.2
vue 2.6.14

Details

I'm using vue-echarts with vitest.
But vitest throw the following error:

SyntaxError: Unexpected token 'export'
 ❯ Object.compileFunction https:/vitest-dev-vitest-fhmvl9.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:341311
 ❯ wrapSafe https:/vitest-dev-vitest-fhmvl9.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:218270
 ❯ Module._compile https:/vitest-dev-vitest-fhmvl9.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:218638
 ❯ Module._extensions..js https:/vitest-dev-vitest-fhmvl9.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:219666
 ❯ Module.load https:/vitest-dev-vitest-fhmvl9.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:217692
 ❯ Module._load https:/vitest-dev-vitest-fhmvl9.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:215263

Module /home/projects/vitest-dev-vitest-fhmvl9/node_modules/echarts/core.js:20 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "echarts" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    deps: {
      inline: [
        "echarts"
      ]
    }
  }
}

According to the comment of vitest member vitest-dev/vitest#1452 (comment) , this is because vue-charts points to cjs entry that uses require which is not intercepted by vitest.

See also his comment in another issue of vue-echarts here: #601 (comment)

Reproduction

stackblitz.com/edit/vitest-dev-vitest-fhmvl9

@Justineo
Copy link
Member

Let's keep this open. We'll work on this once ECharts and ZRender fix this on their side.

@AndreyYolkin
Copy link

Let's keep this open. We'll work on this once ECharts and ZRender fix this on their side.

I bumped issue in apache/echarts repo, may be you need to leave the comment about it in apache/echarts#16709

@maartenbrakkee
Copy link

For anybody interested to fix it in their project with echarts 5.4.0 and vue-echarts 6.2.3:

  • add patch-package and setup the postinstall script ("postinstall": "patch-package",)
  • create a folder named patches in the root folder of your project
  • add the following files to the patches folder
  • run npm install / yarn install

echarts+5.4.0.patch:

diff --git a/node_modules/echarts/package.json b/node_modules/echarts/package.json
index 9ee583c..cd4513e 100644
--- a/node_modules/echarts/package.json
+++ b/node_modules/echarts/package.json
@@ -1,5 +1,6 @@
 {
   "name": "echarts",
+  "type": "module",
   "version": "5.4.0",
   "description": "Apache ECharts is a powerful, interactive charting and data visualization library for browser",
   "license": "Apache-2.0",

vue-echarts+6.2.3.patch:

diff --git a/node_modules/vue-echarts/package.json b/node_modules/vue-echarts/package.json
index a571fde..174515f 100644
--- a/node_modules/vue-echarts/package.json
+++ b/node_modules/vue-echarts/package.json
@@ -1,5 +1,13 @@
 {
   "name": "vue-echarts",
+  "type": "module",
+  "exports": {
+    ".": {
+      "require": "./dist/index.cjs.js",
+      "import": "./dist/index.esm.js",
+      "types": "./dist/index.d.ts"
+    }
+  },
   "version": "6.2.3",
   "description": "Vue.js component for Apache ECharts.",
   "author": "GU Yiling <justice360@gmail.com>",

@AndreyYolkin
Copy link

For anybody interested to fix it in their project with echarts 5.4.0 and vue-echarts 6.2.3:

  • add patch-package and setup the postinstall script ("postinstall": "patch-package",)
  • create a folder named patches in the root folder of your project
  • add the following files to the patches folder
  • run npm install / yarn install

echarts+5.4.0.patch:

diff --git a/node_modules/echarts/package.json b/node_modules/echarts/package.json
index 9ee583c..cd4513e 100644
--- a/node_modules/echarts/package.json
+++ b/node_modules/echarts/package.json
@@ -1,5 +1,6 @@
 {
   "name": "echarts",
+  "type": "module",
   "version": "5.4.0",
   "description": "Apache ECharts is a powerful, interactive charting and data visualization library for browser",
   "license": "Apache-2.0",

vue-echarts+6.2.3.patch:

diff --git a/node_modules/vue-echarts/package.json b/node_modules/vue-echarts/package.json
index a571fde..174515f 100644
--- a/node_modules/vue-echarts/package.json
+++ b/node_modules/vue-echarts/package.json
@@ -1,5 +1,13 @@
 {
   "name": "vue-echarts",
+  "type": "module",
+  "exports": {
+    ".": {
+      "require": "./dist/index.cjs.js",
+      "import": "./dist/index.esm.js",
+      "types": "./dist/index.d.ts"
+    }
+  },
   "version": "6.2.3",
   "description": "Vue.js component for Apache ECharts.",
   "author": "GU Yiling <justice360@gmail.com>",

Yes, I also walked this path, but it's becomming impossible when I convert my project into npm package. Now I'm trying to find a way to prevent installation of vue-echarts in project root node_modules, but in my package root instead

@phlegx
Copy link

phlegx commented Jun 23, 2023

Hi!

If using with Vite, Node Vite dev server and Echarts v5.4.2 I get the following error using this code:

import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { PieChart } from 'echarts/charts'
import { TitleComponent, TooltipComponent, LegendComponent } from 'echarts/components'
import VChart, { THEME_KEY } from 'vue-echarts'

use([CanvasRenderer, PieChart, TitleComponent, TooltipComponent, LegendComponent])

Error

node_modules/echarts/core.js:20
export * from './lib/export/core.js';
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    ...

@kingyue737
Copy link
Contributor Author

Meet this issue again in Nuxt with SSR enabled. https://nuxt.com/docs/guide/concepts/esm#what-kinds-of-problems-can-there-be

Need conditional-exports in a Node.js ESM context

@kingyue737
Copy link
Contributor Author

Let's keep this open. We'll work on this once ECharts and ZRender fix this on their side.

Both zrender v5.5 and echarts v5.5 have been released 🎉

The dependency resize-detector also needs to be fixed

@lnoss
Copy link

lnoss commented Feb 19, 2024

Let's keep this open. We'll work on this once ECharts and ZRender fix this on their side.

Both zrender v5.5 and echarts v5.5 have been released 🎉

The dependency resize-detector also needs to be fixed

Just in time for me.
Relevant links: apache/echarts#19513 and ecomfe/zrender#1051.

@mdoesburg
Copy link

@Justineo Any timeline on this? Would be really appreciated. Resorting to patching atm.

@Justineo
Copy link
Member

Currently blocked by apache/echarts#19663 (we have TS issues at #766). We'll resolve this one after apache/echarts#19663 is resolved.

@Justineo Justineo mentioned this issue May 11, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants