Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
Compiled with problems 'firebase' is not defined

Okay, so the error is coming from line 37 where I am attempting to collect the timestamp for each post and then direct that information to my firebase storage. I can't quite figure what's causing the error or how I'm getting the error as I have imported my firebase.js file.

import React, { useState } from 'react';
import { Button } from '@material-ui/core';
import { storage, db } from './firebase';

function ImageUpload({username}) {
    const [image, setImage] = useState(null);
    const [progress, setProgress] = useState(0);
    const [caption, setCaption] = useState('');

const handleChange = (e) => {
    if (e.target.files[0]) {
        setImage(e.target.files[0]);
    }
};

const handleUpload = () => {
    const uploadTask = storage.ref('images/${image.name}').put(image);

    uploadTask.on(
        'state_changed',
        (snapshot) => {
            const progress = Math.round(
                (snapshot.bytesTransferred / snapshot.totalBytes) *100
            );
            setProgress(progress);
        },
        (error) => {
            console.log(error);
        },
        () => {
            storage
            .ref("images")
            .child(image.name)
            .getDownloadURL()
            .then(url => {
                db.collection("posts").add({
                    timestamp: firebase.firestore.FieldValue.serverTimestamp(),
                    caption: caption,
                    imageUrl: url,
                    username: username
                })
            })
        }
    )
}

return (
    <div>
        <input type="text" placeholder='Caption' onChange={event => setCaption(event.target.value)} value={caption}/>
        <input type="file" onChange={handleChange} />
        <Button className="imageUpload" onClick ={handleUpload}>Upload</Button>
    </div>
)

} export default ImageUpload

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I solved the issue by including the line

import firebase from 'firebase/compat/app';

into the head of the page.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!