\r\n\u003C/template>\r\n\r\n```\r\n\r\n- `index.md`:\r\n\r\n```md\r\n---\r\nlayout: home\r\n---\r\n\r\n\u003Cscript setup>\r\nimport { useData } from 'vitepress'\r\n\u003C/script>\r\n\r\n{{ useData() }}\r\n```\r\n\r\nSee \u003Chttps://stackblitz.com/edit/vite-x3jrgk>.\n\n### Expected behavior\n\nThere should be no such warning.\n\n### System Info\n\n```sh\nSystem:\r\n OS: macOS 13.5\r\n CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\r\n Memory: 224.85 MB / 16.00 GB\r\n Shell: 5.9 - /bin/zsh\r\n Binaries:\r\n Node: 20.5.1 - /usr/local/bin/node\r\n npm: 9.8.0 - /usr/local/bin/npm\r\n pnpm: 8.6.6 - /usr/local/bin/pnpm\r\n Browsers:\r\n Chrome: 116.0.5845.110\r\n Edge: 115.0.1901.188\r\n Safari: 16.6\r\n npmPackages:\r\n vitepress: 1.0.0-rc.4 => 1.0.0-rc.4\n```\n\n\n### Additional context\n\n_No response_\n\n### Validations\n\n- [X] Check if you're on the [latest VitePress version](https://github.com/vuejs/vitepress/releases/latest).\n- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)\n- [X] Read the [docs](https://vitepress.dev).\n- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.",[2935],{"name":2868,"color":2869},2856,"Imports from vitepress in markdown files lead to reexport warning","2023-09-03T00:04:43Z","https://github.com/vuejs/vitepress/issues/2856",0.6591415,{"description":2942,"labels":2943,"number":2945,"owner":2871,"repository":2872,"state":2873,"title":2946,"updated_at":2947,"url":2948,"score":2949},"### Describe the bug\n\n项目中使用了 highlightjs 作为代码预览高亮工具。开发时并未发现异常,但是在构建时提示错误\r\n```text\r\nbuild error:\r\n file:///C:/demo-code/vitepress-error/docs/.vitepress/.temp/app.js:7\r\nimport hljsVuePlugin from \"@highlightjs/vue-plugin\";\r\n ^^^^^^^^^^^^^\r\nSyntaxError: The requested module '@highlightjs/vue-plugin' does not provide an export named 'default'\r\n at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)\r\n at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)\r\n at async Promise.all (index 0)\r\n at async ESMLoader.import (node:internal/modules/esm/loader:385:24)\r\n at async build (file:///C:/demo-code/vitepress-error/node_modules/.pnpm/vitepress@1.0.0-alpha.45/node_modules/vitepress/dist/node/serve-ebe7f464.js:42286:24)\r\n ELIFECYCLE Command failed with exit code 1.\r\n```\r\n一开始我怀疑是该库存在问题,但是在常规 vue 应用中使用并构建都是没问题的。\n\n### Reproduction\n\n最小复现\r\n```text\r\nhttps://github.com/SaberA1ter/vitepress-error-demo\r\n```\r\n组件在 ```docs/.vitepress/theme/index.js``` 中注册,报错也是发生于此\n\n### Expected behavior\n\n开发正常,但是构建报错。\n\n### System Info\n\n```shell\nwin11\r\n\r\nnodejs: v16.15.1\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.",[2944],{"name":2868,"color":2869},1905,"build 报错: SyntaxError: The requested module '@highlightjs/vue-plugin' does not provide an export named 'default'","2023-02-17T00:04:39Z","https://github.com/vuejs/vitepress/issues/1905",0.66072613,{"description":2951,"labels":2952,"number":2957,"owner":2871,"repository":2872,"state":2873,"title":2958,"updated_at":2959,"url":2960,"score":2961},"Vite might be removing/deprecating it's CJS API is near future (https://github.com/vitejs/vite/discussions/13928) which will impact VitePress' CJS API as well.\r\n\r\n**Edit: Let's wait on discussion at Vite's side to conclude and we will try to follow their footsteps. But, it is recommended to use ESM APIs for anything new you might be building.**\r\n\r\n~~Most of the projects already appear to be using the import syntax. A quick [GitHub code search](https://github.com/search?q=/require%5C%28%5Cs*%5B%22'%5Dvitepress%5B%22'%5D/+NOT+is:fork&type=code) shows about 20 public projects doing `require('vitepress')`. Exploring more, over half of them appear to be on `vitepress@0.x` branch. Leaving less than 10 projects that might need minor refactoring.~~\r\n\r\n`import` syntax in `config.js` file when `\"type\": \"module\"` is not specified in nearest package.json also uses the CJS build. Might be difficult to estimate the impact. But for most of the cases where people are using import without type module or mjs/mts extension the migration should be straight forward -- either change the file extension or project level type.\r\n\r\nMigration:\r\n\r\n```ts\r\n// use .mjs/.mts file extension if can't use `\"type\": \"module\"`\r\n\r\n// change\r\nconst { defineConfig } = require('vitepress')\r\n\r\nmodule.exports = {/*...*/}\r\n\r\n// to\r\nimport { defineConfig } from 'vitepress'\r\n\r\nexport default {/*...*/}\r\n\r\n// or since it's just a type helper simply do something like this\r\n\r\n/** @type {ReturnType\u003Ctypeof import('vitepress').defineConfig>} */\r\nmodule.exports = {/*...*/}\r\n\r\n// change\r\nconst { createMarkdownRenderer } = require('vitepress')\r\n // ^ or any async API like createServer, build, resolveConfig, resolveSiteData\r\n\r\nasync fn() {\r\n const md = await createMarkdownRenderer(/*...*/)\r\n}\r\n\r\n// to\r\nasync fn() {\r\n const { createMarkdownRenderer } = await import('vitepress')\r\n const md = await createMarkdownRenderer(/*...*/)\r\n}\r\n```\r\n\r\n---\r\n\r\n~~For maintainers, we will need to use [jiti](https://github.com/unjs/jiti) for the CLI and remove CJS stuff from rollup config.~~\r\n\r\nCLI won't need any changes, it's already CJS compatible and uses ESM output. Only rollup related changes need to be done.\r\n\r\nRollout plan:\r\n\r\nLet's log a warning for now if someone `require`'s the package. We can drop the CJS API by RC.\r\n\r\n/cc @kiaking @zonemeen ",[2953,2954],{"name":2925,"color":2926},{"name":2955,"color":2956},"keep-open","96DAA7",2703,"Moving VitePress' Node API as ESM only","2023-08-08T10:21:50Z","https://github.com/vuejs/vitepress/issues/2703",0.66072947,{"description":2963,"labels":2964,"number":2966,"owner":2871,"repository":2872,"state":2873,"title":2967,"updated_at":2968,"url":2969,"score":2970},"### Is your feature request related to a problem? Please describe.\n\nThe outputs ESM entries are not fully compatible with native ESM actually, take the following as example\r\n\r\nhttps://unpkg.com/browse/vitepress@1.0.0-alpha.4/dist/client/index.js\r\n\r\nAll relative file paths should be ended with correct `.js` extension, and `/index.js` can not be omitted anymore.\r\n\r\nThat's being said, we should use `moduleResolution: \"Node16\"` instead.\r\n\r\nAnd when the user enables `type: \"module\"` in their `package.json` or `.vitepress/package.json`, all temporary `.js` files in `.vitepress/.temp` would be considered as ESM only, and now it would emit error:\r\n\r\n```log\r\nvitepress v1.0.0-alpha.4\r\n- building client + server bundles...\r\n@alauda/chart doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have \"type\": \"module\" or an .mjs extension for the entry point). Please contact the package author to fix.\r\nquill-image-uploader doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have \"type\": \"module\" or an .mjs extension for the entry point). Please contact the package author to fix.\r\n✓ building client + server bundles...\r\n- rendering pages...\r\n✖ rendering pages...\r\nbuild error:\r\n ReferenceError: exports is not defined in ES module scope\r\nThis file is being treated as an ES module because it has a '.js' file extension and '/home/jenkins/agent/workspace/frontend/frontend-vision-docs/docs/.vitepress/package.json' contains \"type\": \"module\". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.\r\n at file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/docs/.vitepress/.temp/app.js:2:25\r\n at ModuleJob.run (node:internal/modules/esm/module_job:195:25)\r\n at async Promise.all (index 0)\r\n at async ESMLoader.import (node:internal/modules/esm/loader:337:24)\r\n at async renderPage (file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/node_modules/vitepress/dist/node/serve-05342c3d.js:39534:25)\r\n at async build (file:///home/jenkins/agent/workspace/frontend/frontend-vision-docs/node_modules/vitepress/dist/node/serve-05342c3d.js:39853:9)\r\nerror Command failed with exit code 1.\r\ninfo Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.\r\nscript returned exit code 1\r\n```\n\n### Describe the solution you'd like\n\nEnable `moduleResolution: \"Node16\"` and add a `package.json` into `.vitepress/.temp` with `type: \"commonjs\"` for now, and migrate all outputs files as pure ESM later.\n\n### Describe alternatives you've considered\n\nWe can use `.cjs` files extensions for files outputs in `.vitepress/.temp`\n\n### Additional context\n\nReference https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing\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] Read the [Contributing Guidelines](https://github.com/vuejs/vitepress/blob/main/.github/contributing.md).\n- [X] Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.",[2965],{"name":2925,"color":2926},917,"Better support for `type: \"module\"` from user","2023-01-21T14:28:36Z","https://github.com/vuejs/vitepress/issues/917",0.6609019,["Reactive",2972],{},["Set"],["ShallowReactive",2975],{"$fTRc1wZytZ_XrK4EfJfei_Sz-An4H4Yy6syhVxH_PVJc":-1,"$fEOQjABf5rMMeGnRV3hQSSS1ZgwNL-riRDVARl2O4SK4":-1},"/vuejs/vitepress/2411"]