I create .env.local and have there a few variables, when I use one of them it returns undefined, it's just for one specific variable
const firebaseConfig = {
apiKey: process.env.REACT_APP_API_KEY, //this one work
authDomain: process.env.REACT_APP_AUTH_DOMAIN, //this one work
projectId: process.env.REACT_APP_PROJECT_ID, //this one is undefined, and I don't know why, the naming is correct, when it's equal to a simple string its works
storageBucket: process.env.REACT_APP_STORAGE_BUCKET, //and other work
messagingSenderId: process.env.REACT_APP_MESSAGING_SENSER_ID,
appId: process.env.REACT_APP_APP_ID,
measurementId: process.env.REACT_APP_MEASUREMENT_ID
};
I tried to change name, it's not helping, I google it, but find nothing
CodePudding user response:
It is likely that the process.env.REACT_APP_PROJECT_ID environment variable is undefined because it is not set in your environment.
To resolve this issue, you can either set the environment variable in your operating system or in your code by using a library like dotenv.
If you use dotenv library, you will have to create a .env file in the root directory of your project and add the following line:
REACT_APP_PROJECT_ID=your-project-id
Replace your-project-id with the actual value of your Firebase project ID.
After that, at the very top of your code, you will have to import the dotenv library:
require('dotenv').config();