antfu-collective / vite-ssg

Static site generation for Vue 3 on Vite
MIT License
1.33k stars 136 forks source link

"window is not defined" with vue-router #253

Closed evdevru closed 2 years ago

evdevru commented 2 years ago

How to fix it ? "vue-router": "^4.0.15"

`.vite-ssg-temp/main.mjs 476.33 KiB .vite-ssg-temp/assets/style.b3155112.css 55.31 KiB

[vite-ssg] An internal error occurred. [vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues C:\Users\sonic\Documents\csgo-dark-dashboard\node_modules\vue-router\dist\vue-router.cjs.js:505
const { history, location } = window; ^

ReferenceError: window is not defined at useHistoryStateNavigation (C:\Users\sonic\Documents\csgo-dark-dashboard\node_modules\vue-router\dist\vue-router.cjs.js:505:35) at createWebHistory (C:\Users\sonic\Documents\csgo-dark-dashboard\node_modules\vue-router\dist\vue-router.cjs.js:597:31) at file:///C:/Users/sonic/Documents/csgo-dark-dashboard/.vite-ssg-temp/main.mjs:1625:14 at ModuleJob.run (node:internal/modules/esm/module_job:195:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:337:24) at async build (file:///C:/Users/sonic/Documents/csgo-dark-dashboard/node_modules/vite-ssg/dist/chunks/build.mjs:167:87) at async Object.handler (file:///C:/Users/sonic/Documents/csgo-dark-dashboard/node_modules/vite-ssg/dist/node/cli.mjs:20:3)`

the-illarionov commented 1 year ago

@evdevru how you dealed with that problem?

Bernankez commented 1 year ago

@evdevru how you dealed with that problem?

Did you have an unused router in your project? I have an unused exported router in my routes/index, and it causes the problem.

JeffreyArts commented 9 months ago

As an addition, also remove the history option as described in this issue

import { createWebHistory } from "vue-router"
const routerOptions = {
  routes,
  history: createWebHistory()
}

Should become

const routerOptions = {
  routes,
}