antfu-collective / vite-ssg

Static site generation for Vue 3 on Vite
MIT License
1.27k stars 129 forks source link

Can'not build with vue-select #390

Open mgbetegan opened 6 months ago

mgbetegan commented 6 months ago

Describe the bug

I'm currently facing a problem where I installed vue-select for my project and I'm unable to create the build when I run vite-ssg build it gives the following error bellow

Capture d’écran 2023-12-31 à 10 17 46

Reproduction

add vue-select in a vite project, when run the build with vite-ssg it thorws the error

System Info

/node_modules/vue-select/dist/vue-select.es.js:13
import { openBlock as a, createElementBlock as h, createElementVNode as u, resolveDirective as K, normalizeClass as A, renderSlot as r, normalizeProps as d, guardReactiveProps as c, Fragment as B, renderList as L, createTextVNode as v, toDisplayString as D, createBlock as b, resolveDynamicComponent as _, createCommentVNode as O, mergeProps as k, toHandlers as j, withDirectives as w, vShow as P, createVNode as $, Transition as R, withCtx as z, withModifiers as F } from "vue";
^^^^^^

SyntaxError: Cannot use import statement outside a module

Used Package Manager

yarn

Validations

JeffreyArts commented 5 months ago

The issue is that vue-select is using methods that are not available in a nodeJS environment. In this case, the import method. A workaround I apply to these situations is to wrap the import statement in an if statement that checks for the window variable.

let vueSelect

if (typeof window !== "undefined") {
    (async () => {
        const vueSelect = await import("vue-select")
    })()
}