\r\n\r\nIt is inevitable to use `document` in `vitepress` many times, but how to avoid the packaging error when` vitepress` uses the server-side rendering method?\r\n\r\nAre there any third-party plug-in recommendations or configuration items?\n\n### Reproduction\n\n```vue\r\n\u003Cscript setup>\r\n console.log(document)\r\n\u003C/script>\r\n```\r\n\r\n\r\n\n\n### Expected behavior\n\nBuild ok\n\n### System Info\n\n```shell\n\"vitepress\": \"^1.0.0-alpha.4\",\r\n\"vue\": \"^3.2.33\"\n```\n\n\n### Additional context\n\n_No response_\n\n### Validations\n\n- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)\n- [X] Read the [docs](https://vitepress.vuejs.org).\n- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.",[2899],{"name":2900,"color":2901},"question","5D5FAE",1120,"document is not defined","2023-01-21T14:28:51Z","https://github.com/vuejs/vitepress/issues/1120",0.7223205,{"description":2908,"labels":2909,"number":2913,"owner":2869,"repository":2870,"state":2871,"title":2914,"updated_at":2915,"url":2916,"score":2917},"### Describe the bug\n\nuse yarn2 build docs\n\n### Reproduction\n\nyarn \r\n\r\nyarn add vitepress -D\r\nvitepress serve docs\n\n### Expected behavior\n\nbuild success\n\n### System Info\n\n```shell\n❯ node -v\r\nv16.13.2\r\n❯ npm -v\r\n8.4.1\r\n❯ yarn -v\r\n3.1.1\r\n\r\n\"vitepress\": \"^0.22.1\"\n```\n\n\n### Additional context\n\n\r\n\n\n### Validations\n\n- [X] Follow our [Code of Conduct](https://vuejs.org/coc)\n- [X] Read the [docs](https://vitepress.vuejs.org/).\n- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.",[2910],{"name":2911,"color":2912},"docs","0075ca",531,"Your application tried to access vue, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound","2023-01-21T14:34:10Z","https://github.com/vuejs/vitepress/issues/531",0.72292215,{"description":2919,"labels":2920,"number":2922,"owner":2869,"repository":2870,"state":2871,"title":2923,"updated_at":2924,"url":2925,"score":2926},"\u003C!--\r\nNOTE:\r\nVitePress is still WIP, and it is not compatible with VuePress.\r\nPlease do not open issue about default theme missing features or something doesn't work like VuePress.\r\n-->\r\n\r\n**Describe the bug**\r\nAfter running npx vitepress, I open the browser and load the address of http://localhost:3000, but I get a error.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\nPS D:\\桌面\\demo> npx vitepress\r\nvitepress v0.5.0\r\nvite v1.0.0-rc.4\r\nlistening at http://localhost:3000\r\n[vite] Failed to resolve module import \"vue/dist/vue.runtime.esm-bundler.js.0.0-rc.5@vuedist\u000bue.runtime.esm-bundler.js\". (imported by /@app/components/Debug.vue)\r\n\r\n**Expected behavior**\r\nGetting \"Hello Vitepress\" in browser.\r\n\r\n**System Info**\r\n- vitepress version: v0.5.0\r\n- vite version: v1.0.0-rc.4\r\n- Node version: 12.14.0\r\n- OS version:10.0.19041 暂缺 Build 19041\r\n\r\n**Additional context**\r\n尤大大,I am you big fan.\r\n",[2921],{"name":2866,"color":2867},65,"服务启动之后,进入地址报错","2023-01-21T16:25:36Z","https://github.com/vuejs/vitepress/issues/65",0.72353715,{"description":2928,"labels":2929,"number":2931,"owner":2869,"repository":2870,"state":2871,"title":2932,"updated_at":2933,"url":2934,"score":2935},"### Describe the bug\r\n\r\nWhen extending the default theme with pre-built Vue component, dev server, build stages behave differently when install the pre-built Vue component as workspace dependency and as a regular npm registry dependency.\r\n\r\nThe integrate the pre-built Vue component consists native elements with reference to one of the field `lang` returned by a composable `useData()` from `vitepress`:\r\n\r\n```vue\r\n\u003Cscript setup lang=\"ts\">\r\nimport { useData } from 'vitepress'\r\n\r\nconst { lang } = useData()\r\n\u003C/script>\r\n\r\n\u003Ctemplate>\r\n \u003Cdiv>\r\n \u003Ch1>TryUseData\u003C/h1>\r\n \u003Cp>lang: {{ lang }}\u003C/p>\r\n \u003C/div>\r\n\u003C/template>\r\n```\r\n\r\nThe bundled esm module looks like this:\r\n\r\n```js\r\nimport { defineComponent as n, openBlock as a, createElementBlock as o, createElementVNode as e, toDisplayString as r, unref as l } from \"vue\";\r\nimport { useData as s } from \"vitepress\";\r\nconst c = /* @__PURE__ */ e(\"h1\", null, \"TryUseData\", -1), f = /* @__PURE__ */ n({\r\n __name: \"TryUseData\",\r\n setup(p) {\r\n const { lang: t } = s();\r\n return (_, m) => (a(), o(\"div\", null, [\r\n c,\r\n e(\"p\", null, \"lang: \" + r(l(t)), 1)\r\n ]));\r\n }\r\n});\r\nexport {\r\n f as TryUseData\r\n};\r\n```\r\n\r\nThis pre-built component works well and expected when install the bundled package in Monorepo, but if you try to build when install it as a regular dependency, error appears:\r\n\r\n```shell\r\nnr docs:build\r\n\r\n> @ docs:build /vitepress-usedata-repro-monorepo/repros/regular-dep\r\n> vitepress build\r\n\r\n\r\n vitepress v1.0.0-rc.12\r\n\r\n✓ building client + server bundles...\r\nbuild error:\r\nfile://vitepress-usedata-repro-monorepo/repros/regular-dep/node_modules/.pnpm/vitepress-usedata-repro-monorepo-components@1.0.0_vitepress@1.0.0-rc.12_vue@3.3.4/node_modules/vitepress-usedata-repro-monorepo-components/dist/index.es.mjs:2\r\nimport { useData as s } from \"vitepress\";\r\n ^^^^^^^\r\nSyntaxError: The requested module 'vitepress' does not provide an export named 'useData'\r\n at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)\r\n at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)\r\n ELIFECYCLE Command failed with exit code 1.\r\n```\r\n\r\n### What I tried\r\n\r\n#### With a locally `\u003CClientOnly>`\r\n\r\nSince the `ClientOnly` is not exported and it cannot be correctly processed in external UI libraries, I tried to use a local wrapped `\u003CClientOnly>` component with a ref boolean value `mounted` to conditional render the children components with the `v-if` render, it worked when used as regular dependency.\r\n\r\n#### With a `\u003CSuspense>` and lazy import\r\n\r\nI referenced [Importing in Mounted Hook](https://vitepress.dev/guide/ssr-compat#importing-in-mounted-hook) section of VitePress documentation, it suggests:\r\n\r\n> ```ts\r\n> onMounted(() => {\r\n> import('./lib-that-access-window-on-import').then((module) => {\r\n> // use code\r\n> })\r\n> })\r\n> ```\r\n\r\nHowever, VitePress uses `provide` and `inject` API from Vue for `useData()` and `inject()` is not possible to be called outside of `setup()` function, so I have to wrapped the `lang` into a child component with a `v-model:lang` as `v-model`, and `await import('vitepress')` to get it working.\r\n\r\n### Thoughts\r\n\r\nThough, I find my way to solve it, but **why i18n is not possible to obtain when building when VitePress is a static site?** I think there should be some bugs or behaviors behind the scene that I don't know about which causes these errors while behaves differently.\r\n\r\n### Reproduction\r\n\r\nFull reproduction requires a private npm registry to simulate the npm bahavior, therefore I created a detailed reproduction as a repository rather than a StackBlitz container: https://github.com/nekomeowww/reproduction-vitepress-usedata-error\r\n\r\n> I cannot find a better automated way to achieve this, if you have any better and easier reproduction method, please share it with me!\r\n\r\n### Expected behavior\r\n\r\n1. The 'useData' is accessible from 'vitepress' when in runtime and build time, it shouldn't produces errors.\r\n2. Workaround to obtain the i18n locale code. Shouldn't be impossible to obtain it when generating static sites.\r\n3. Workaround for pre-built Vue components.\r\n\r\n### System Info\r\n\r\n```Text\r\nSystem:\r\n OS: macOS 13.4.1\r\n CPU: (10) arm64 Apple M1 Pro\r\n Memory: 82.81 MB / 16.00 GB\r\n Shell: 5.9 - /bin/zsh\r\n Binaries:\r\n Node: 18.17.1 - ~/.volta/tools/image/node/18.17.1/bin/node\r\n Yarn: 3.6.1 - ~/.volta/tools/image/yarn/3.6.1/bin/yarn\r\n npm: 9.6.7 - ~/.volta/tools/image/node/18.17.1/bin/npm\r\n pnpm: 8.6.12 - ~/.volta/bin/pnpm\r\n Browsers:\r\n Chrome: 117.0.5938.88\r\n Chrome Canary: 119.0.6016.0\r\n Safari: 16.5.2\r\n```\r\n\r\n\r\n### Additional context\r\n\r\nI found out a statement says the vitepress is specially handled in issue #1900:\r\n\r\n> As mentioned above, The 'vitepress' dose not provide an export named 'useData'. The actual dependence is 'vitepress/dist/client/index.js'\r\n> Because the 'vitepress' is specially processed in the development environment. You will not be confused in vitepress project when debugging API Reference. But vitepress is actually a CLI role.\r\n\r\nI tried to integrate and import `vitepress/dist/client/index.js` instead of import it directly in the Vue component, however, another build error would appear when building the Vue component (yes, before install and import into a VitePress `theme/index.ts`):\r\n\r\n```shell\r\nnr build \r\n\r\n> vitepress-usedata-repro-monorepo-components@1.0.7 build /packages/vitepress-usedata-repro-monorepo-components\r\n> vite build && vue-tsc --declaration --emitDeclarationOnly\r\n\r\nvite v4.4.9 building for production...\r\n✓ 7 modules transformed.\r\n✓ built in 225ms\r\n[vite]: Rollup failed to resolve import \"@siteData\" from \"/plugins/node_modules/.pnpm/vitepress@1.0.0-rc.12_@algolia+client-search@4.19.1_@types+node@20.6.0_less@4.2.0_search-insights@2.8.2/node_modules/vitepress/dist/client/app/data.js\".\r\nThis is most likely unintended because it can break your application at runtime.\r\nIf you do want to externalize this module explicitly add it to\r\n`build.rollupOptions.external`\r\nerror during build:\r\nError: [vite]: Rollup failed to resolve import \"@siteData\" from \"/plugins/node_modules/.pnpm/vitepress@1.0.0-rc.12_@algolia+client-search@4.19.1_@types+node@20.6.0_less@4.2.0_search-insights@2.8.2/node_modules/vitepress/dist/client/app/data.js\".\r\nThis is most likely unintended because it can break your application at runtime.\r\nIf you do want to externalize this module explicitly add it to\r\n`build.rollupOptions.external`\r\n at viteWarn (file:///plugins/node_modules/.pnpm/vite@4.4.9_@types+node@20.6.0_less@4.2.0/node_modules/vite/dist/node/chunks/dep-df561101.js:48142:27)\r\n at onRollupWarning (file:///plugins/node_modules/.pnpm/vite@4.4.9_@types+node@20.6.0_less@4.2.0/node_modules/vite/dist/node/chunks/dep-df561101.js:48174:9)\r\n at onwarn (file:///plugins/node_modules/.pnpm/vite@4.4.9_@types+node@20.6.0_less@4.2.0/node_modules/vite/dist/node/chunks/dep-df561101.js:47902:13)\r\n at file:///plugins/node_modules/.pnpm/rollup@3.28.1/node_modules/rollup/dist/es/shared/node-entry.js:24194:13\r\n at Object.logger [as onLog] (file:///plugins/node_modules/.pnpm/rollup@3.28.1/node_modules/rollup/dist/es/shared/node-entry.js:25867:9)\r\n at ModuleLoader.handleInvalidResolvedId (file:///plugins/node_modules/.pnpm/rollup@3.28.1/node_modules/rollup/dist/es/shared/node-entry.js:24780:26)\r\n at file:///plugins/node_modules/.pnpm/rollup@3.28.1/node_modules/rollup/dist/es/shared/node-entry.js:24740:26\r\n ELIFECYCLE Command failed with exit code 1.\r\n```\r\n\r\nBut when I set the suggested `build.rollupOptions.external` with `vitepress/dist/client/index.js`, build passed with no error. But another failed to resolve error would appear when building for VitePress as a regular dependency:\r\n\r\n```shell\r\nbuild error:\r\nError [ERR_MODULE_NOT_FOUND]: Cannot find module '/vitepress-usedata-repro-monorepo/repros/regular-dep/node_modules/.pnpm/vitepress@1.0.0-rc.12_@algolia+client-search@4.20.0_search-insights@2.8.2/node_modules/vitepress/dist/client/app/data' imported from /vitepress-usedata-repro-monorepo/repros/regular-dep/node_modules/.pnpm/vitepress@1.0.0-rc.12_@algolia+client-search@4.20.0_search-insights@2.8.2/node_modules/vitepress/dist/client/index.js\r\n at new NodeError (node:internal/errors:405:5)\r\n at finalizeResolution (node:internal/modules/esm/resolve:324:11)\r\n at moduleResolve (node:internal/modules/esm/resolve:943:10)\r\n at defaultResolve (node:internal/modules/esm/resolve:1129:11)\r\n at nextResolve (node:internal/modules/esm/loader:163:28)\r\n at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)\r\n at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)\r\n at ModuleWrap.\u003Canonymous> (node:internal/modules/esm/module_job:77:40)\r\n at link (node:internal/modules/esm/module_job:76:36)\r\n ELIFECYCLE Command failed with exit code 1.\r\n```\r\n\r\n### Validations\r\n\r\n- [X] Check if you're on the [latest VitePress version](https://github.com/vuejs/vitepress/releases/latest).\r\n- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)\r\n- [X] Read the [docs](https://vitepress.dev).\r\n- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.",[2930],{"name":2866,"color":2867},2987,"inconsistent error behavior about The requested module `'vitepress'` does not provide an export named `'useData'`","2023-09-27T00:04:18Z","https://github.com/vuejs/vitepress/issues/2987",0.7243493,{"description":2937,"labels":2938,"number":2939,"owner":2869,"repository":2870,"state":2871,"title":2940,"updated_at":2941,"url":2942,"score":2943},"\u003C!--\r\nNOTE:\r\nVitePress is still WIP, and it is not compatible with VuePress.\r\nPlease do not open issue about default theme missing features or something doesn't work like VuePress.\r\n-->\r\n\r\n**Describe the bug**\r\nWhen using a custom theme, importing composables like `useRoute` from `\"vitepress\"` in the Layout component also imports the styles for the default theme.\r\n\r\n**To Reproduce**\r\n\r\n1. Follow the [Getting Started guide](https://vitepress.vuejs.org/guide/getting-started.html) to create a new site\r\n2. Create `docs/.vitepress/theme/Layout.vue` with the following contents:\r\n\r\n```vue\r\n\u003Ctemplate>\r\n \u003CContent />\r\n\u003C/template>\r\n\r\n\u003Cscript setup>\r\n// import { useRoute } from \"vitepress\";\r\n// const route = useRoute();\r\n\u003C/script>\r\n```\r\n\r\n3. Create `docs/.vitepress/theme/index.js` with the following contents:\r\n\r\n```js\r\nimport Layout from \"./Layout.vue\";\r\n\r\nexport default {\r\n Layout,\r\n};\r\n```\r\n\r\n4. Run `yarn docs:dev` and open http://localhost:3000. Note the heading doesn't have any styles applied to it:\r\n\r\n\r\n\r\n5. Uncomment the lines in the `\u003Cscript setup>` section in `docs/.vitepress/theme/Layout.vue`. Note the heading now has the default styles applied to it, even though we only imported `useRoute`:\r\n\r\n\r\n\r\n**Expected behavior**\r\nThe heading should remain unstyled since we aren't explicitly importing any styles.\r\n\r\n**System Info**\r\n- vitepress version: v0.9.2\r\n- vite version: v1.0.0-rc.13\r\n- Node version: v12.20.0\r\n- OS version: macOS Catalina 10.15.7\r\n\r\n**Additional context**\r\nI had a quick look at the Vitepress code and it looks like the problem might be to do with this line: https://github.com/vuejs/vitepress/blob/309aa7a8d0e7ab08c1c9db258c74709a66b295cb/src/client/app/exports.ts#L29\r\n\r\nAdding the following to `docs/.vitepress/config.js`:\r\n\r\n```javascript\r\nmodule.exports = {\r\n alias: {\r\n \"/@default-theme/index\": \"/@theme/empty.js\",\r\n },\r\n};\r\n```\r\n\r\n...and creating an empty file `docs/.vitepress/theme/empty.js` prevents the default styles being applied.\r\n",[],182,"Importing default composables also imports default theme's styles","2023-01-21T16:23:59Z","https://github.com/vuejs/vitepress/issues/182",0.7251976,{"description":2945,"labels":2946,"number":2948,"owner":2869,"repository":2870,"state":2871,"title":2949,"updated_at":2950,"url":2951,"score":2952},"### Describe the bug\n\n### 我在打包的时候出现了Build error, window is not defined\r\n\r\n`theme/index.js`\r\n`\r\nimport MyLayout from '../../../components/MyLayout.vue'\r\n`\r\n`\r\nexport default {\r\n ...DefaultTheme,\r\n Layout: MyLayout\r\n}\r\n`\r\n其中的MyLayout是一个扩展组件 请问这样怎么使用ClientOnly包装呢?\r\n\r\n\n\n### Reproduction\n\n无\n\n### Expected behavior\n\n希望能正常Build 不报build error window is not defined这个错误\n\n### System Info\n\n```shell\n\"vitepress\": \"^1.0.0-alpha.29\",\n```\n\n\n### Additional context\n\n\r\n\n\n### Validations\n\n- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)\n- [X] Read the [docs](https://vitepress.vuejs.org).\n- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.",[2947],{"name":2866,"color":2867},1808,"Layout组件怎么使用ClientOnly包装","2023-01-26T00:04:06Z","https://github.com/vuejs/vitepress/issues/1808",0.7257338,{"description":2954,"labels":2955,"number":2957,"owner":2869,"repository":2870,"state":2871,"title":2958,"updated_at":2959,"url":2960,"score":2961},"### Describe the bug\r\n\r\nHi, I am trying to import and use a custom Markdown renderer inside a component but it looks like the `createMarkdownRenderer` function is not exported.\r\n\r\n```\r\nUncaught SyntaxError: The requested module '/@fs/Users/xyz/.github/xyz/node_modules/vitepress/dist/client/index.js?v=61ac765b' does not provide an export named 'createMarkdownRenderer' (at EndpointExample.vue:2:10)\r\n```\r\n\r\nHowever, according to TypeScript types exported from VitePress, `createMarkdownRenderer` should be available for use.\r\n\r\n### Reproduction\r\n\r\n```vue\r\n\u003Cscript setup lang=\"ts\">\r\nimport { createMarkdownRenderer } from \"vitepress\";\r\n\r\nconst props = defineProps\u003C{\r\n requests: { type: string; content: string; }[];\r\n response: string;\r\n}>();\r\n\r\n// `createMarkdownRenderer` is not exported from vitepress.\r\nconst md = await createMarkdownRenderer(\".\");\r\nconst response = md.render(props.response);\r\n\u003C/script>\r\n```\r\n\r\n### Expected behavior\r\n\r\nThe function `createMarkdownRenderer` should be exported as it is available from TypeScript types. If it should not, then remove the `createMarkdownRenderer` type export.\r\n\r\n### System Info\r\n\r\n```shell\r\nSystem:\r\n OS: macOS 12.6\r\n CPU: (8) arm64 Apple M1 Pro\r\n Memory: 116.75 MB / 16.00 GB\r\n Shell: 5.8.1 - /bin/zsh\r\n Binaries:\r\n Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node\r\n Yarn: 1.22.19 - ~/.yarn/bin/yarn\r\n npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm\r\n Browsers:\r\n Brave Browser: 108.1.46.144\r\n Chrome: 108.0.5359.124\r\n Firefox: 103.0.2\r\n Safari: 16.0\r\n```\r\n\r\n\r\n### Additional context\r\n\r\nPlease note that I am trying to create a custom `markdownRenderer` so that I can create a code render from my component props.\r\n\r\n### Validations\r\n\r\n- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)\r\n- [X] Read the [docs](https://vitepress.vuejs.org).\r\n- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.",[2956],{"name":2866,"color":2867},1752,"The requested module does not provide an export named 'createMarkdownRenderer'","2023-01-21T14:16:58Z","https://github.com/vuejs/vitepress/issues/1752",0.7268765,["Reactive",2963],{},["Set"],["ShallowReactive",2966],{"$fTRc1wZytZ_XrK4EfJfei_Sz-An4H4Yy6syhVxH_PVJc":-1,"$f0g96bIGwLHpNrAhAfwyWXBnYQqiGCVo8FpxDTdV0c5E":-1},"/vuejs/vitepress/2391"]