From a522f1ee3a75c88f2ed41a52250bd445d55d7011 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 15 Aug 2023 10:48:57 +0100 Subject: [PATCH] fix(nuxi): ignore error if nitro is not enabled on bridge (#22642) --- packages/nuxi/package.json | 1 + packages/nuxi/src/commands/build.ts | 9 +++++++-- pnpm-lock.yaml | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/package.json b/packages/nuxi/package.json index 54c7ee4e93..2f166704cb 100644 --- a/packages/nuxi/package.json +++ b/packages/nuxi/package.json @@ -41,6 +41,7 @@ "listhen": "1.3.0", "mlly": "1.4.0", "mri": "1.2.0", + "nitropack": "^2.5.2", "ohash": "1.1.3", "pathe": "1.1.1", "perfect-debounce": "1.0.0", diff --git a/packages/nuxi/src/commands/build.ts b/packages/nuxi/src/commands/build.ts index e87a22f546..c41f7e668c 100644 --- a/packages/nuxi/src/commands/build.ts +++ b/packages/nuxi/src/commands/build.ts @@ -1,5 +1,6 @@ import { relative, resolve } from 'pathe' import { consola } from 'consola' +import type { Nitro } from 'nitropack' // we are deliberately inlining this code as a backup in case user has `@nuxt/schema<3.7` import { writeTypes as writeTypesLegacy } from '../../../kit/src/template' @@ -38,8 +39,12 @@ export default defineNuxtCommand({ } }) - // Use ? for backward compatibility for Nuxt <= RC.10 - const nitro = useNitro?.() + let nitro: Nitro | undefined + // In Bridge, if nitro is not enabled, useNitro will throw an error + try { + // Use ? for backward compatibility for Nuxt <= RC.10 + nitro = useNitro?.() + } catch {} await clearBuildDir(nuxt.options.buildDir) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed92885800..3ec02abb95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -316,6 +316,9 @@ importers: mri: specifier: 1.2.0 version: 1.2.0 + nitropack: + specifier: ^2.5.2 + version: 2.5.2 ohash: specifier: 1.1.3 version: 1.1.3