From c824905b99c66af219a6cc2336d4f40adfc4e6de Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 20 Dec 2021 12:19:31 +0000 Subject: [PATCH] fix(schema): handle null/undefined values in `runtimeConfig` (#2456) --- packages/nitro/src/rollup/config.ts | 3 ++- packages/schema/src/config/_common.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/nitro/src/rollup/config.ts b/packages/nitro/src/rollup/config.ts index f32c7b10c4..095513a5b9 100644 --- a/packages/nitro/src/rollup/config.ts +++ b/packages/nitro/src/rollup/config.ts @@ -14,6 +14,7 @@ import wasmPlugin from '@rollup/plugin-wasm' import inject from '@rollup/plugin-inject' import { visualizer } from 'rollup-plugin-visualizer' import * as unenv from 'unenv' +import devalue from '@nuxt/devalue' import type { Preset } from 'unenv' import { sanitizeFilePath } from 'mlly' @@ -164,7 +165,7 @@ export const getRollupConfig = (nitroContext: NitroContext) => { 'process.env.NUXT_STATIC_VERSION': JSON.stringify(nitroContext._nuxt.staticAssets.version), 'process.env.NUXT_FULL_STATIC': nitroContext._nuxt.fullStatic as unknown as string, 'process.env.NITRO_PRESET': JSON.stringify(nitroContext.preset), - 'process.env.RUNTIME_CONFIG': JSON.stringify(nitroContext._nuxt.runtimeConfig), + 'process.env.RUNTIME_CONFIG': devalue(nitroContext._nuxt.runtimeConfig), 'process.env.DEBUG': JSON.stringify(nitroContext._nuxt.dev) } })) diff --git a/packages/schema/src/config/_common.ts b/packages/schema/src/config/_common.ts index 3e8fd9df3f..ffa99215f1 100644 --- a/packages/schema/src/config/_common.ts +++ b/packages/schema/src/config/_common.ts @@ -714,6 +714,6 @@ export default { * @version 3 */ publicRuntimeConfig: { - $resolve: (val, get) => defu(val, { app: get('app') }) + $resolve: (val = {}, get) => ({ ...val, app: defu(val.app, get('app')) }) }, }