Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/vinext/src/config/next-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. " +
Expand Down Expand Up @@ -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;
}
}

Expand Down
27 changes: 26 additions & 1 deletion tests/next-config.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;

Expand Down
Loading