From 41e5258744c12eba3ba0205fbe22207c0ea545ba Mon Sep 17 00:00:00 2001 From: James Date: Thu, 19 Mar 2026 18:09:59 +0000 Subject: [PATCH 1/2] fix: throw errors when next config parse fails --- packages/vinext/src/config/next-config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vinext/src/config/next-config.ts b/packages/vinext/src/config/next-config.ts index cb057a3be..4c59de328 100644 --- a/packages/vinext/src/config/next-config.ts +++ b/packages/vinext/src/config/next-config.ts @@ -274,7 +274,9 @@ function warnConfigLoadFailure(filename: string, err: Error): void { stack.includes("next-intl/plugin") || stack.includes("next-intl/dist"); - console.warn(`[vinext] Failed to load ${filename}: ${msg}`); + console.log(); + console.error(`[vinext] Failed to load ${filename}: ${msg}`); + console.log(); if (isNextIntlPlugin) { console.warn( "[vinext] Hint: createNextIntlPlugin() is not needed with vinext. " + @@ -338,12 +340,12 @@ export async function loadNextConfig( return await unwrapConfig({ default: mod }, phase); } catch (e2) { warnConfigLoadFailure(filename, e2 as Error); - return null; + throw e2; } } warnConfigLoadFailure(filename, e as Error); - return null; + throw e; } } From d6fe0228fa2f562663dce1081e12f55ff69e005d Mon Sep 17 00:00:00 2001 From: James Date: Thu, 19 Mar 2026 18:18:57 +0000 Subject: [PATCH 2/2] add unit test --- tests/next-config.test.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/next-config.test.ts b/tests/next-config.test.ts index 358c96db7..0c381c7f8 100644 --- a/tests/next-config.test.ts +++ b/tests/next-config.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, afterEach, vi } from "vite-plus/test"; +import { describe, it, expect, afterEach, vi, beforeEach } from "vite-plus/test"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; @@ -18,6 +18,31 @@ function makeTempDir(): string { return fs.mkdtempSync(path.join(os.tmpdir(), "vinext-config-test-")); } +describe("invalid config files", () => { + let tmpDir: string; + + beforeEach(() => { + tmpDir = makeTempDir(); + }); + + afterEach(() => { + vi.restoreAllMocks(); + if (tmpDir) { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }); + + it("should throw an error when loading a config fails", async () => { + fs.writeFileSync(path.join(tmpDir, "package.json"), `{ "type": "module" }`); + fs.writeFileSync( + path.join(tmpDir, "next.config.js"), + `const path = require('path');\n module.exports = {};\n`, + ); + + await expect(loadNextConfig(tmpDir, PHASE_PRODUCTION_BUILD)).rejects.toThrow(); + }); +}); + describe("loadNextConfig phase argument", () => { let tmpDir: string;