From ca7d6c94e3e824ccee1ed2f95386f5e46f40595c Mon Sep 17 00:00:00 2001 From: DEls Date: Mon, 26 Oct 2026 02:22:44 +0200 Subject: [PATCH] fix(build): unbreak next build type check on vitest NODE_ENV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deployment failed at "Running TypeScript ..." with: vitest.config.ts(7,13): error TS2540: Cannot assign to 'NODE_ENV' because it is a read-only property. Next's next/types/global declares NODE_ENV on ProcessEnv as `readonly`. tsconfig includes **/*.ts, so next build type-checks vitest.config.ts and the direct assignment from 34017d8 took every deploy down with it. Object.assign has no source-to-target assignability constraint, so it compiles while still writing NODE_ENV through process.env's setter — React still gets its development build, which is what exposes `act`. Verified: tsc --noEmit clean, 3839 tests pass, npm run build succeeds. --- vitest.config.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vitest.config.ts b/vitest.config.ts index d5a060c..a6d590e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,7 +4,14 @@ import path from "node:path"; // React only exposes `act` in its development build, so a shell with // NODE_ENV=production would break every component test. Vitest only sets // NODE_ENV when it is unset, so force it. -process.env.NODE_ENV = "test"; +// +// Next's `next/types/global` declares NODE_ENV on ProcessEnv as `readonly`, +// so a plain `process.env.NODE_ENV = "test"` fails the type check that +// `next build` runs over this file (tsconfig includes **/*.ts) and takes +// the whole deployment down. Object.assign has no source-to-target +// assignability constraint, so it compiles while still writing the value +// through process.env's setter at runtime. +Object.assign(process.env, { NODE_ENV: "test" }); export default defineConfig({ resolve: {