-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
wasp start
fails with TS2783: 'NODE_ENV' is specified more than once, so this usage will be overwritten
when ProcessEnv
interface is augmented with NODE_ENV
property.
The explanation
Wasp generates the following code:
export const env = ensureEnvSchema(
{ NODE_ENV: serverDevSchema.shape.NODE_ENV.value, ...process.env },
serverEnvSchema,
)
This is fine since process.env
is usually declared as an object that doesn't contain NODE_ENV
e.g. check out @types/node
User reported in Discord that they had next
installed which extended the ProcessEnv
similar to this:
declare namespace NodeJS {
interface ProcessEnv {
NODE_ENV: "development" | "production";
}
}
When the ProcessEnv
interface includes NODE_ENV
spreading process.env
creates duplicate NODE_ENV
properties which Typescript considers to be a type error.
For the simplest reproduction check out this Typescript playground example
Possible solution
Update Wasp's env.ts
generation to use destructuring:
const { NODE_ENV = serverDevSchema.shape.NODE_ENV.value, ...restEnv } = process.env;
export const env = ensureEnvSchema(
{ NODE_ENV, ...restEnv },
serverEnvSchema,
)
Copilot
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working