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

[Bug] Support dual packaging #17189

Closed
kingyue737 opened this issue Jun 9, 2022 · 3 comments
Closed

[Bug] Support dual packaging #17189

kingyue737 opened this issue Jun 9, 2022 · 3 comments
Labels
bug en This issue is in English pending We are not sure about whether this is a bug/new feature.

Comments

@kingyue737
Copy link

Version

5.3.2

Link to Minimal Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-kcuvdv

Steps to Reproduce

  1. Open the link
  2. Wait for the test to end

Current Behavior

Vitest throw the following error:

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/echarts.test.ts [ test/echarts.test.ts ]
SyntaxError: Cannot use import statement outside a module
 ❯ Object.compileFunction https:/vitest-dev-vitest-kcuvdv.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:341311
 ❯ wrapSafe https:/vitest-dev-vitest-kcuvdv.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:218270
 ❯ Module._compile https:/vitest-dev-vitest-kcuvdv.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:218638
 ❯ Module._extensions..js https:/vitest-dev-vitest-kcuvdv.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:219666
 ❯ Module.load https:/vitest-dev-vitest-kcuvdv.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:217692
 ❯ Module._load https:/vitest-dev-vitest-kcuvdv.w.staticblitz.com/blitz.ad37e903755d89e0f5d9999e69be73a0c6cb6bcc.js:6:215263

Module /home/projects/vitest-dev-vitest-kcuvdv/node_modules/echarts/lib/core/echarts.js:26 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"
      ]
    }
  }
}

Expected Behavior

ECharts should be imported correctly as an ES Module by vitest.

ECharts may need to support dual packaging mentioned in this guide.

Environment

- OS: Windows 11
- Browser: Chrome 
- Framework: Vue@2 + Vite

Reproduction with `vue-echarts` here: [stackblitz.com/edit/vitest-dev-vitest-fhmvl9](stackblitz.com/edit/vitest-dev-vitest-fhmvl9)

Any additional comments?

This issue has been mentioned before in #16599 but is closed now.

See also the comments of vitest member:
ecomfe/vue-echarts#601 (comment)
vitest-dev/vitest#1452 (comment)

@kingyue737 kingyue737 added the bug label Jun 9, 2022
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Jun 9, 2022
@iKnowMagic
Copy link

I am having the same error. :(

@sabifa
Copy link

sabifa commented May 8, 2023

Same issue here, any update?

@100pah
Copy link
Member

100pah commented Jan 22, 2024

Fixed by #19513

@100pah 100pah closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug en This issue is in English pending We are not sure about whether this is a bug/new feature.
Projects
None yet
Development

No branches or pull requests

4 participants