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

Vitest: Unexpected token 'export' #20707

Open
golubeva-webmaster opened this issue Jan 21, 2025 · 0 comments
Open

Vitest: Unexpected token 'export' #20707

golubeva-webmaster opened this issue Jan 21, 2025 · 0 comments
Assignees
Labels
bug en This issue is in English pending We are not sure about whether this is a bug/new feature.

Comments

@golubeva-webmaster
Copy link

Version

^5.4.3

Link to Minimal Reproduction

Visual Studio Code

Steps to Reproduce

Good time! Guys, importing charts "knocks down" tests written on vitest:
SyntaxError: Unexpected token 'export'

Although the recommended setting is written in my config...

Image

//vitest.config.ts
/// <reference types="vitest/config" />
import { defineConfig, mergeConfig } from "vitest/config"
// import { mergeConfig } from "vitest/config"
// import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { quasar, transformAssetUrls } from "@quasar/vite-plugin"
import path from "path"
import { Panel } from "@stereotech/cloud-components"

export default mergeConfig(
  {
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
    },
    plugins: [
      vue({
        template: {
          compilerOptions: {
            isCustomElement: (tag) => ["panel1"].includes(tag),
          },
          transformAssetUrls,
        },
      }),
      quasar(),
    ],
  },
  defineConfig({
    test: {
      globals: true, //& Чтобы не импортировать expect, describe, it в каждом тесте
      environment: "jsdom",
      coverage: {
        provider: "v8",
      },
      server: {
        deps: {
          inline: ["echarts"],
        },
      },
      // environmentMatchGlobs: [["tests/components/**", "jsdom"]],
    },
    // plugins: [svelte({ hot: !process.env.VITEST })],
  }),
)
//vite.config.ts
import { defineConfig, loadEnv, UserConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { quasar, transformAssetUrls } from "@quasar/vite-plugin"
import electron from "vite-plugin-electron/simple"
import path from "path"

const webConfig: UserConfig = {
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  plugins: [
    vue({
      template: { transformAssetUrls },
    }),
    quasar(),
  ],
}

const panelConfig: UserConfig = {
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  plugins: [
    vue({
      template: { transformAssetUrls },
    }),
    quasar(),

    electron({
      main: {
        entry: "electron/main.ts",
      },
      preload: {
        input: "electron/preload.ts",
      },
      renderer: {},
    }),
  ],
}

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), "")
  if (env.VITE_APP_PLATFORM === "panel" && mode === "production") {
    //Electron build
    return panelConfig
  } else {
    return webConfig
  }
})

Current Behavior

Module C:/WorkProjects/Ste-App-Client-2/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: {
server: {
deps: {
inline: [
"echarts"
]
}
}
}
}

Expected Behavior

No errors

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

No response

@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 Jan 21, 2025
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

2 participants