Custom theme sub-packages in the mono repo cannot use Node-related APIs. #4589
-
https://stackblitz.com/~/github.com/shellRaining/shellRaining-blog I plan to create a VitePress theme, and organized my VitePress blog into a mono repo. The directory structure is as above you can see in Next is my blog post subpackage, which installs the theme subpackage via the workspace (I hope users can directly install my subpackage and use my custom theme). Its when I run [plugin vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/Users/shellraining/Documents/blog/packages/theme/src/config.ts". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
x Build failed in 2.19s
✖ building client + server bundles...
build error:
../theme/src/config.ts (7:9): "readFileSync" is not exported by "__vite-browser-external", imported by "../theme/src/config.ts".
file: /Users/shellraining/Documents/blog/packages/theme/src/config.ts:7:9
5: import markdownItSub from "markdown-it-sub";
6: import markdownItTaskLists from "markdown-it-task-lists";
7: import { readFileSync } from "node:fs";
^
8:
9: const APPEARANCE_KEY = "shellRaining-blog-theme";
at getRollupError (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/parseAst.js:397:41)
at error (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/parseAst.js:393:42)
at Module.error (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:16603:16)
at Module.traceVariable (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:17052:29)
at ModuleScope.findVariable (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:14709:39)
at ChildScope.findVariable (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:5582:38)
at FunctionScope.findVariable (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:5582:38)
at FunctionBodyScope.findVariable (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:5582:38)
at BlockScope.findVariable (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:5582:38)
at BlockScope.findVariable (file:///Users/shellraining/Documents/vitepress/node_modules/.pnpm/rollup@4.34.7/node_modules/rollup/dist/es/shared/node-entry.js:5582:38)
error: script "build" exited with code 1 However, if the you can test in stackblitz, it's output is same as my computer |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You'll need 2 entrypoints in your theme. One for client, one for node. Currently both server side and browser code is being compiled into single file by tsup. Ah, I see you're already doing that. I think you need to remove export * from config here - https://github.com/shellRaining/shellRaining-blog/blob/main/packages/theme/src/index.ts |
Beta Was this translation helpful? Give feedback.
You'll need 2 entrypoints in your theme. One for client, one for node. Currently both server side and browser code is being compiled into single file by tsup.
Ah, I see you're already doing that. I think you need to remove export * from config here - https://github.com/shellRaining/shellRaining-blog/blob/main/packages/theme/src/index.ts