From ee56cf0a8b45da6ff1295cbecc7547b3bb05ef4b Mon Sep 17 00:00:00 2001 From: MinarKotonoha <42364602+chengzhuo5@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:16:29 +0800 Subject: [PATCH] fix: optimize the splicing method of serverEntry to make it compatible with bun (#398) --- src/node/build.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node/build.ts b/src/node/build.ts index ea56192..c789368 100644 --- a/src/node/build.ts +++ b/src/node/build.ts @@ -109,7 +109,12 @@ export async function build(ssgOptions: Partial = {}, viteConfig const prefix = (format === 'esm' && process.platform === 'win32') ? 'file://' : '' const ext = format === 'esm' ? '.mjs' : '.cjs' - const serverEntry = join(prefix, ssgOut, parse(ssrEntry).name + ext) + + /** + * `join('file://')` will be equal to `'file:\'`, which is not the correct file protocol and will fail to be parsed under bun. + * It is changed to '+' splicing here. + */ + const serverEntry = prefix + join(ssgOut, parse(ssrEntry).name + ext).replace(/\\/g, '/') const _require = createRequire(import.meta.url)