Skip to content Skip to sidebar Skip to footer

How To Use Es6(esm) Imports/exports In Cloud Functions

import functions from 'firebase-functions'; import UtilModuler from '@utilModuler' exports.helloWorld = functions.https.onRequest((request, response) => { response.send('Hello

Solution 1:

"devDependencies": {
  "@babel/core": "^7.2.0",
  "@babel/preset-env": "^7.2.0",
  "@babel/register": "^7.0.0"
}

.babelrc

{
  "presets": ["@babel/preset-env"]
}

entry point node.js app

require("@babel/register")({})

// Import the rest of our application.module.exports = require('./index.js')

Solution 2:

It looks like, ESM support has been added by the latest version of the firebase CLI (https://github.com/firebase/firebase-tools/releases/tag/v9.15.0):

$ npm install -g firebase-tools # Get the latest firebase-cli$ firebase deploy --only functions# Deploy as usual

and

  1. You must select nodejs14 runtime.
  2. You must manually include latest version of @google-cloud/functions-framework dependency. e.g.
// package.json
...
  "engines": {
    "node": "14"
  },
  "type": "module",
  "dependencies": {
    "@google-cloud/functions-framework": "^1.9.0",
    ...
  },

and an example function:

// index.jsimport functions from"firebase-functions";

exportconst helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
});

Post a Comment for "How To Use Es6(esm) Imports/exports In Cloud Functions"