PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] Why I get UNDEFINED from ENVIRONMENT VARIABLE in REACT App?

 August 19, 2022     environment-variables, javascript, reactjs     No comments   

Issue

Unfortunately, it's a pretty simple question, but I can't find the answer.

Don't have an access to environment variables in some file.

I use create-react-app (^16.11.0)

  • file .env in the root folder near package.json
  • variable declared as REACT_APP_API=http://localhost:4000
  • call variable as process.env.REACT_APP_API
  • the server has been restarted many times

I have an access to the variable in some folder but in another don't.

below link to files structure

workflow structure

Thanks a lot!


Solution

THE PROBLEM WAS FOUND! As often happens, the reason is funny.

When typing process.env.REACT_APP_API, my IDE automaticlly added an import at the top of the file

import process from "process"; 

That's why i can't access to process.env. in one specific file.

Import removed, problem solved



Answered By - Mara
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing