Is there any way of extending the process.env.NODE_ENV so that different environment variables are in different builds.
This piece of code process.env.NODE_ENV === 'staging'
produces this error This condition will always return 'false' since the types '"production" | "test"' and '"staging"' have no overlap.
To my understanding this is because only 'development' | 'production' | 'test'
variables are allowed in NODE_ENV.
I was looking at these questions and its answers:
- using process.env in TypeScript
- This condition will always return 'false' since the types '"development" | "production" | "test"' and '"local"' have no overlap.ts(2367)
- Extending process.env variable types in Nodejs with Typescript
I created index.d.ts file in the root directory where package.json file is and added:
declare namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'staging';
}
}
Should I include this file in some config?
Is there any way on building the project using command with variables i.e: npm build --staging
or react-scripts build --staging
so that the code below makes sense:
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
url = DEV_URL;
} else if (process.env.NODE_ENV === 'staging') {
url = STAGING_URL;
}
else if (process.env.NODE_ENV === 'production') {
url = PRODUCTION_URL;
}
else {
url = DEV_URL;
}
If you have any suggestions on how to solve this in a different way, please feel free to add them.