I have a JS file holding my firebase config that I import into my index.html, and it works perfectly when the values within the JS file are hardcoded
<script src="./firebase-config.js"></script>
<script type="module">
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
import { firebaseConfig } from './firebase-config.js';
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
export var firebaseConfig = {
apiKey: "<my-api-key>",
authDomain: "<my-auth-domain>",
databaseURL: "<my-database-url>",
projectId: "<my-project-id>",
storageBucket: "<my-storage-bucket>",
messagingSenderId: "<my-messaging-sender-id>",
appId: "<my-app-id>",
measurementId: "<my-measurement-id>"
};
But when I try to use env variables within the JS file like
apiKey: process.env.FIREBASE_API_KEY
, the key doesn't get picked up and I get an error that firebase isn't initialised when I run the project. The .env file is also placed in the web folder