Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda