react-native-dotenv: Multi-env doesn't change
Multi-env doesn’t change. I always get variables from .env.development, most likely because this file is the first in the folder. I have the folder with 3 files: .env.development .env.staging .env.production. I’ve tried cleaning, reinstalling, and many more options, but nothing seems to work.
My npm scripts:
"start:development": "NODE_ENV=development npx react-native start --reset-cache",
"start:staging": "NODE_ENV=staging npx react-native start --reset-cache",
"start:production": "NODE_ENV=production npx react-native start --reset-cache",
I also use the next script:
"babel-clear": "rimraf node_modules/.cache/babel-loader/*,"
My babel config:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: './config/.env',
blocklist: null,
allowlist: null,
safe: false,
allowUndefined: true,
},
],
],
};
In my file index.js
import { URL } from '@env';
“react”: “17.0.1”, “react-native”: “0.64.1”, “react-native-dotenv”: “^3.0.0”,
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 26 (11 by maintainers)
I updated and it works great with npm scripts. Thank you very much for your work.
will be fixed in
v3.1.1@goatandsheep I asked yesterday about whether I can set the NODE_ENV constant from other places, for example, from gitlab CI? Now I tried to build a test assembly and got a production environment everywhere. Could this be a library problem? What are the ways to create a constant NODE_ENV?
Also tell me please, can I get a variable NODE_ENV from other places? For example from gitlab CI?
Working on it here https://github.com/goatandsheep/react-native-dotenv-metro-demo
Could you give me an example?
I understand correctly that NODE_ENV indicates which file to use?
Updated. Please see in my question