From 8530a8fee78d87abf7b9d8409097f4c77f7f53e2 Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Fri, 22 Oct 2021 08:47:54 -0600 Subject: [PATCH] Throw friendly error if renderer provides viteConfig in a bad format --- packages/astro/src/core/create-vite.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 72fbfe27717c..d34fdfa2a444 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -78,12 +78,17 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig, for (const name of astroConfig.renderers) { try { const { default: renderer } = await import(name); - if (renderer && typeof renderer.viteConfig === 'function') { + if (!renderer) continue; + // if a renderer provides viteConfig(), call it and pass in results + if (renderer.viteConfig) { + if (typeof renderer.viteConfig !== 'function') { + throw new Error(`${name}: viteConfig(options) must be a function! Got ${typeof renderer.viteConfig}.`); + } const rendererConfig = await renderer.viteConfig({ mode: inlineConfig.mode, command: inlineConfig.mode === 'production' ? 'build' : 'serve' }); // is this command true? viteConfig = vite.mergeConfig(viteConfig, rendererConfig) as vite.InlineConfig; } } catch (err) { - throw new Error(`${name}\n ${err}`); + throw new Error(`${name}: ${err}`); } }