'Can not Access variables of .env file

In my React app, I was trying to access some variables from .env.local but every time I print It it shows undefined.

// src/.env.local
REACT_APP_SECRET_CODE=123456 
// In different component
console.log(process.env.REACT_APP_SECRET_CODE);
output: undefined

Note: I tried to use .env file as well, but did not work.

React Script version is 5.0.1



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source