From bd80d27a499c535da21c02cbcdc8cd85ed6be4e4 Mon Sep 17 00:00:00 2001 From: Jeremy Ye <51736428+jremye@users.noreply.github.com> Date: Fri, 13 May 2022 19:00:14 +0800 Subject: [PATCH] fix(vite): add `file://` protocol to `vite-node` entry file path (#4966) --- packages/vite/src/vite-node.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/vite-node.ts b/packages/vite/src/vite-node.ts index 20491a7564..d4d5985e38 100644 --- a/packages/vite/src/vite-node.ts +++ b/packages/vite/src/vite-node.ts @@ -1,3 +1,4 @@ +import { pathToFileURL } from 'node:url' import { createApp, createError, defineEventHandler, defineLazyEventHandler } from 'h3' import { ViteNodeServer } from 'vite-node/server' import fse from 'fs-extra' @@ -97,12 +98,15 @@ export async function prepareDevServerEntry (ctx: ViteBuildContext) { } process.env.NUXT_VITE_NODE_OPTIONS = JSON.stringify(viteNodeServerOptions) + const serverResolvedPath = resolve(distDir, 'runtime/vite-node.mjs') + const manifestResolvedPath = resolve(distDir, 'runtime/client.manifest.mjs') + await fse.writeFile( resolve(ctx.nuxt.options.buildDir, 'dist/server/server.mjs'), - `export { default } from ${JSON.stringify(resolve(distDir, 'runtime/vite-node.mjs'))}` + `export { default } from ${JSON.stringify(pathToFileURL(serverResolvedPath).href)}` ) await fse.writeFile( resolve(ctx.nuxt.options.buildDir, 'dist/server/client.manifest.mjs'), - `export { default } from ${JSON.stringify(resolve(distDir, 'runtime/client.manifest.mjs'))}` + `export { default } from ${JSON.stringify(pathToFileURL(manifestResolvedPath).href)}` ) }