7

I'm using create-react-app and my code looks like this

const firebaseConfig = {
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_DATABASE_URL,
  projectId: process.env.REACT_APP_PROJECT_ID,
  storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_APP_ID
};

The .env file variables are accessbile in development. But on deploying site in netlify I'm getting error.

I'm getting the error like this

Uncaught FirebaseError: projectId must be a string in FirebaseApp.options
    at new t (https://movie-base.netlify.com/static/js/2.84dcc854.chunk.js:1:412130)
    at Function.e.databaseIdFromApp (https://movie-base.netlify.com/static/js/2.84dcc854.chunk.js:1:692685)
    at new e (https://movie-base.netlify.com/static/js/2.84dcc854.chunk.js:1:688595)
    at Object.firestore (https://movie-base.netlify.com/static/js/2.84dcc854.chunk.js:1:720410)
    at e._getService (https://movie-base.netlify.com/static/js/2.84dcc854.chunk.js:1:2448)
    at e.<computed> [as firestore] (https://movie-base.netlify.com/static/js/2.84dcc854.chunk.js:1:4280)
    at Object.p [as firestore] (https://movie-base.netlify.com/static/js/2.84dcc854.chunk.js:1:3996)
    at Module.435 (https://movie-base.netlify.com/static/js/main.dfb179dd.chunk.js:1:41914)
    at f (https://movie-base.netlify.com/movie/263115:1:994)
    at Object.222 (https://movie-base.netlify.com/static/js/main.dfb179dd.chunk.js:1:110)

Issue Resolved : Error was mine, Auto publishing is turned off in netlify, So netlify.toml variables didn't applied on latest build.

ali emili
  • 538
  • 2
  • 6
  • 19
Mistborn
  • 86
  • 6
  • 1
    did you also set your environment variables in `netlify.toml`? Or on your netlify dashboard under settings? – evayly May 21 '19 at 20:00
  • I'm only using .env for environment variables. Did I also set in netlify.toml ? – Mistborn May 21 '19 at 20:02
  • Yes, the only Channels netlify will consider are the netlify.toml or your dashboard settings. see: https://www.netlify.com/docs/continuous-deployment/#environment-variables – evayly May 21 '19 at 20:04
  • 2
    @GopiKrishna I did this one week ago exactly like you, without a `.toml` file- worked for me. How did you set up Netlify's variables? Please note that you should use `REACT_APP_FIREBASE_API_KEY` instead of `process.env.REACT_APP_FIREBASE_API_KEY` at the Netlify configuration. – Bennett Dams May 21 '19 at 20:10
  • @BennettDams I used REACT_APP_FIREBASE_API_KEY in netlify environment variable. But the preview deploy is working, but not the main one. Preview Deploy : https://5ce45c3391ef84000a5e034a--movie-base.netlify.com/ Main Site: https://movie-base.netlify.com/ – Mistborn May 21 '19 at 20:19
  • @GopiKrishna what mechanism you used for login and session maintain. – Vishal kumar singhvi Apr 28 '20 at 11:20
  • Hi did you able to solve it yet? – KYin Apr 20 '22 at 08:35

0 Answers0