So I'm trying to connect my Javascript application to Firebase. I understand that I need to use a bundler to do this, and my preferred method is Parcel.JS. I run my Parcel.JS script with the following code in my package.json file:
"main": "./public/js/bundle.js",
"scripts": {
"watch:js": "parcel watch ./public/js/index.js --dist-dir ./public/js",
This is the code in my index.js file:
import { initializeApp } from 'firebase/app';
import { getAnalytics } from 'firebase/analytics';
const firebaseConfig = {
apiKey: '',
authDomain: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
measurementId: '',
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
Parcel.JS bundles it up into bundle.js as expected, and I reference it at the bottom of my index.pug file as follows:
script(src='/js/bundle.js')
When the page loads, I check the console in Chrome and see the following error message:
Uncaught ReferenceError: require is not defined
at bundle.js:1
Can anyone tell me what I'm doing wrong here? I'm a bit lost.