Skip to content

Variables always undefined on web #533

@shahmir-k

Description

@shahmir-k
  • Asked question in discussions
  • [X ] Tried the troubleshooting Wiki
  • [X ] Followed the migration Wiki
  • [X ] Installed library as devDependency not production dependency

Describe the bug
I have a fully working app on react-native that works on both web and mobile. I am trying to shift away from using hard-coded api urls and put them all into a .env file. When I added react-native-dotenv my program runs just fine, but all the env variables are being returned as undefined.

To Reproduce
Steps to reproduce the behavior:

  1. npx expo install react-native-dotenv
  2. create .env file
  3. import variables from @env
  4. variables print out as undefined :(

Expected behavior
I expected it to return my url string or atleast give an error

Screenshots

Image

Image

Image

Image

Desktop (please complete the following information):

  • OS: [Linux Mint 22 and Windows 10]
  • Browser [Firefox]
  • Version [I don't know]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
The example expo project you posted works, but my program doesn't work... I don't understand why. The only difference is that the example project uses webpack while I rely on just expo to build my web version.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions