Open HERRKIN opened 6 years ago
This would be required for our use case too: we want developers to be able to override configuration as needed (to point to qa/staging environments, or override settings for testing) but want the app to use the prod configuration by default if no env file is present.
I wonder if this can be accomplished using require
style imports and default properties? For example:
const {
APP_URL = 'predefined',
FOO = 'foo_default',
BAR = 'bar_default',
} = require('react-native-dotenv');
This might work since require
style imports are just returning an object and destructured keys would be undefined
.
I had to move to another library, but I will try it soon.
@HERRKIN what library did you move to?
@kylethebaker I tried what you suggested as the following :
const { API_BASE_URL = '' } = require('react-native-dotenv')
but the Metro Bundler fails with the following :
error: bundling failed: Error: Unable to resolve module `path` from `/Users/zedtux/Developments/companion/node_modules/react-native-dotenv/index.js`: Module `path` does not exist in the Haste module map
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`. 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
at ModuleResolver.resolveDependency (/Users/zedtux/Developments/companion/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:161:1460)
at ResolutionRequest.resolveDependency (/Users/zedtux/Developments/companion/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:91:16)
at DependencyGraph.resolveDependency (/Users/zedtux/Developments/companion/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)
at dependencies.map.relativePath (/Users/zedtux/Developments/companion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)
at Array.map (<anonymous>)
at resolveDependencies (/Users/zedtux/Developments/companion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)
at /Users/zedtux/Developments/companion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33
at Generator.next (<anonymous>)
at step (/Users/zedtux/Developments/companion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)
at /Users/zedtux/Developments/companion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473
Switching to react-native-config
package.
I am testing the module, I am trying to do this
APPURL || 'predefinedURL'
but if I ImportAPPURL
and it is not defined in any .env files the app crashes, I was hopping it would come empty so I could evaluate if its empty or null I could use a predifined one, now it is demanding me to use a .env file or it wont start the app at all.I even tried import env from ... ehh error I cannot import env from react native dotenv, I tried import * as env, it doesn't work either.
so I have no use for this lib at the moment.