fix(build): unbreak next build type check on vitest NODE_ENV
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.
This commit is contained in:
parent
88a3a1e1be
commit
ca7d6c94e3
1 changed files with 8 additions and 1 deletions
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue