Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

app crash if no variable present #38

Open
HERRKIN opened this issue Mar 7, 2018 · 5 comments
Open

app crash if no variable present #38

HERRKIN opened this issue Mar 7, 2018 · 5 comments

Comments

@HERRKIN
Copy link

HERRKIN commented Mar 7, 2018

I am testing the module, I am trying to do this APPURL || 'predefinedURL' but if I Import APPURL 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.

@kylethebaker
Copy link

kylethebaker commented Mar 22, 2018

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.

@HERRKIN
Copy link
Author

HERRKIN commented Mar 23, 2018

I had to move to another library, but I will try it soon.

@iRoachie
Copy link

@HERRKIN what library did you move to?

@zedtux
Copy link

zedtux commented Jul 13, 2018

@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

@zedtux
Copy link

zedtux commented Jul 13, 2018

Switching to react-native-config package.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants