react-native-dotenv
react-native-dotenv copied to clipboard
NODE_ENV is undefined
- [x] Tried the troubleshooting Wiki
- [x] Followed the migration Wiki
Describe the bug
After upgrading from 3.2.0 to 3.3.0 my use of process.env.NODE_ENV
returns undefined
. It seems that 3.3.0 added support for process.env
, but maybe clobbers NODE_ENV
? I tried added to the blocklist
, and I have safe
set to true
, but nothing seemed to change the behaviour except downgrading to 3.2.0.
To Reproduce Steps to reproduce the behavior:
- Upgrade to 3.3.0
-
console.log(process.env.NODE_ENV)
- Observe that it outputs
undefined
instead ofdevelopment
orproduction
Expected behavior
The process.env.NODE_ENV
should be untouched.
Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/251
Hi @karlvr I created a branch that added NODE_ENV
to the process.env
test, which seemed to pass (check PR #252 ). I didn't see your thread in the discussions section, but that's okay we're here now. I'm happy to assist further following priority boost
Hello guys, I'm also having this behavior using multi-env.
I can only use multi-env if I set APP_ENV
. My question is if i can have problems with NODE_ENV == undefined
?
babel.config.js
api.cache.invalidate(() => process.env.NODE_ENV);
console.log('env', process.env.NODE_ENV);
console.log('benv', process.env.BABEL_ENV);
console.log('appenv', process.env.APP_ENV);
return {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env',
safe: false,
allowUndefined: true,
},
]...
package.json
"start:dev": "APP_ENV=development expo start -c",
"start:prod": "APP_ENV=production expo start -c"
running production script the logs are:
transform[stdout]: env undefined
transform[stdout]: benv development
transform[stdout]: appenv production
the BABEL_ENV=development
was expected?
I figured out how to reproduce the error and I'm investigating
@goatandsheep thank you for the quick answer. I'm building with expo ba --releaseChannel staging
, but it always points to .env.production
, do you think it has something to do with the above problem? The "benv" log outputs production
.
I figured out how to fix @karlvr 's problem.
@tgwow APP_ENV
is not recommended behaviour and using development
and production
is not supposed to work using APP_ENV
. Recommended behaviour is to use NODE_ENV=development
. See the docs https://github.com/goatandsheep/react-native-dotenv#override-envname
@tgwow look into creating a dev build https://docs.expo.dev/development/getting-started/
im having a similar strange behavior using expo 44 and "react-native-dotenv": "^3.3.1" process.env.NODE_ENV return undefined but process.env have value i dont know how its possible
console.log(process.env);
/*
output:
Object {
"NODE_ENV": "development",
}
*/
console.log(process.env.NODE_ENV);
/*
output:
undefined
*/
RN 0.68.1/react-native-dotenv 3.3.1: If the output of "process.env.NODE_ENV" is undefined, don't set NODE_ENV on "process.env.NODE_ENV", set it on the const value:
const environment = process.env
console.log(environment.NODE_ENV)
@douglascavanaugh thanks, really helped. But why this trick with const environment = process.env
works?
Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/251