vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Build error: ReferenceError: document is not defined

Open Hollelihanqi opened this issue 1 year ago • 4 comments
trafficstars

Is your feature request related to a problem? Please describe.

Whenever I execute pnpm docs:build, I always fail to package successfully and get an error ReferenceError: document is not defined.

Describe the solution you'd like

docs system is built successfully! No error is reported when executing pnpm docs:build. And a successful dist package is packaged.

Describe alternatives you've considered

No response

Additional context

github : https://github.com/Hollelihanqi/qh-ui.git /** @type {import('vitepress').Theme} */

import { h } from "vue"; import VPApp, { NotFound, globals } from "../vitepress"; import DefaultTheme from "vitepress/theme"; // import { define } from '../utils/types'

// import 'uno.css' import "virtual:uno.css"; import './style.css'

import "../vitepress/styles/base.scss";

import ElementPlus from "element-plus"; import "element-plus/dist/index.css"; import YtoUplus from '@yto/custom' import '@yto/custom/index.css'

// import type { Theme } from 'vitepress' export default { extends: DefaultTheme, NotFound, Layout: VPApp, async enhanceApp({ app }) { globals.forEach(([name, Comp]) => { app.component(name, Comp); }); app.use(ElementPlus); app.use(YtoUplus); // @ts-ignore // if (!import.meta.env.SSR) { // const custom = await import('@yto/custom').then((m) => m) // app.use(custom.default) // } }, // Layout() { // return h(DefaultTheme.Layout, null, { // "aside-outline-before": () => h("div", {}, "我是前置内容"), // }); // }, };

Validations

Hollelihanqi avatar Oct 11 '24 04:10 Hollelihanqi

Please share a minimal example using https://vitepress.new and read the docs for possible solutions - https://vitepress.dev/guide/ssr-compat

brc-dd avatar Oct 12 '24 11:10 brc-dd

解决了么,我也遇到同样的问题

TaurusWood avatar Jan 14 '25 10:01 TaurusWood

解决了么,我也遇到同样的问题

zhangMrzhang avatar Apr 07 '25 08:04 zhangMrzhang

我遇到了同样的问题,我解决了,大概情况是需要在onMounted中访问document、window这些浏览器API

nahan-1923 avatar Jun 01 '25 07:06 nahan-1923