From 8fb28470cee4058f438ee5c2a0cd39bdd8f48e35 Mon Sep 17 00:00:00 2001 From: Alex Korytskyi Date: Thu, 21 Apr 2022 00:12:45 +0300 Subject: [PATCH] fix: wrap dynamic import in prerender to fix Windows build failure --- src/prerender.ts | 4 +++- src/rollup/config.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/prerender.ts b/src/prerender.ts index ab0dd49f92..fc4a3ed91a 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -1,3 +1,4 @@ +import { pathToFileURL } from 'url' import { resolve, join } from 'pathe' import { parseURL } from 'ufo' import chalk from 'chalk' @@ -26,7 +27,8 @@ export async function prerender (nitro: Nitro) { await build(nitroRenderer) // Import renderer entry - const { localFetch } = await import(resolve(nitroRenderer.options.output.serverDir, 'index.mjs')) + const serverEntrypoint = resolve(nitroRenderer.options.output.serverDir, 'index.mjs') + const { localFetch } = await import(pathToFileURL(serverEntrypoint).href) // Start prerendering const generatedRoutes = new Set() diff --git a/src/rollup/config.ts b/src/rollup/config.ts index 1d730390c2..a8d21864b0 100644 --- a/src/rollup/config.ts +++ b/src/rollup/config.ts @@ -227,7 +227,7 @@ export const plugins = [ // https://github.com/rollup/plugins/tree/master/packages/alias let buildDir = nitro.options.buildDir // Windows (native) dynamic imports should be file:// urr - if (isWindows && (nitro.options.externals.trace === false)) { + if (isWindows && (nitro.options.externals?.trace === false)) { buildDir = pathToFileURL(buildDir).href } rollupConfig.plugins.push(alias({