From f321a56e63be508e5f478b1de5227a5add2b977f Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Thu, 7 Jul 2022 18:51:42 +0200 Subject: [PATCH] fix(nuxt): use virtual server stub with `ssr: false` (#5773) --- packages/nuxt/src/core/nitro.ts | 6 ++++++ packages/nuxt/src/core/runtime/nitro/renderer.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 4ec5f15bf6..1d67b63524 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -29,6 +29,7 @@ export async function initNitro (nuxt: Nuxt) { handlers, devHandlers: [], baseURL: nuxt.options.app.baseURL, + virtual: {}, runtimeConfig: { ...nuxt.options.runtimeConfig, nitro: { @@ -100,6 +101,11 @@ export async function initNitro (nuxt: Nuxt) { } }) + // Add fallback server for `ssr: false` + if (!nuxt.options.ssr) { + nitroConfig.virtual['#build/dist/server/server.mjs'] = 'export default () => {}' + } + // Extend nitro config with hook await nuxt.callHook('nitro:config', nitroConfig) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 085e5564c2..3562c6cabe 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -35,7 +35,7 @@ const getClientManifest = () => import('#build/dist/server/client.manifest.mjs') .then(r => typeof r === 'function' ? r() : r) // @ts-ignore -const getServerEntry = () => process.env.NUXT_NO_SSR ? Promise.resolve(null) : import('#build/dist/server/server.mjs').then(r => r.default || r) +const getServerEntry = () => import('#build/dist/server/server.mjs').then(r => r.default || r) // -- SSR Renderer -- const getSSRRenderer = lazyCachedFunction(async () => {