Alec Kaczmarek
Alec Kaczmarek

Reputation: 23

Using es6 import statements in firebase functions

So i have been trying to use es6 in firebase functions so I can import like "import App from './src/App.js' . After adding type:"module" to my package.json I am getting the weirdest firebase functions error I have ever seen, and can not for the life of me figure out where it is coming from. Any help would be a amazing. enter image description here

//App.js
import React from "react"; 
const App =()=> {
    return <h1>Hello world!</h1>;
    }
export default App


//index.js
import functions from  "firebase-functions";
import App from "./src/App.js"
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase- 
functions

exports.helloWorld = functions.https.onRequest((request, 
response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

Upvotes: 1

Views: 1498

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50900

The firebase-functions is meant to be used on server-side (in the Cloud function) and not in a client web app. To setup Cloud functions, create a new directory and run firebase init. Follow the instructions and setup Cloud Functions.

The CLI will install all required modules and add a sample function like this:

import functions from  "firebase-functions";

exports.helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

Then you can call your cloud function either by using Firebase SDK or using Fetch API.

Also checkout Getting started with Cloud Functions for Firebase for a detailed explanation.

Upvotes: 2

Related Questions