react-most-wanted icon indicating copy to clipboard operation
react-most-wanted copied to clipboard

Unable to run firebase functions locally the ES6 imports are not working

Open lohanidamodar opened this issue 4 years ago • 8 comments

Hi, I am using firebase-function-tools to write my firebase functions. However I am unable to run firebase functions on emulators locally. Imported import {functions} from 'firebase-functions' , functions is undefined. And there are other imports that are not working too. Is there any solutions. Thank you.

lohanidamodar avatar Jul 15 '20 11:07 lohanidamodar

Hi @lohanidamodar

The import for the functions would look like this:

import * as functions from 'firebase-functions'

For me that works when I publish the functions but I haven't tried it with the emulators. I rather have a project just for development and test everything there ;)

I hope that this can help you. Let me know if you have more issues.

TarikHuber avatar Jul 22 '20 19:07 TarikHuber

Check this out. It looks like it works. We just can't use the import https://twitter.com/tmthyrd/status/1373280164801560577

TarikHuber avatar Apr 13 '21 07:04 TarikHuber

Thanks for providing firebase-function-tools.

Can I use the loadFunctions with ES6? Any sample?

tonprince avatar Sep 03 '21 07:09 tonprince

Did you try it with import loadFunctions from 'firebase-function-tools'

TarikHuber avatar Sep 03 '21 08:09 TarikHuber

Will try again and replace exports with variable.

tonprince avatar Sep 03 '21 14:09 tonprince

@tonprince do you have any updates on this?

TarikHuber avatar Aug 12 '22 17:08 TarikHuber

I switched to new cloud functions 2nd gen.

tonprince avatar Aug 24 '22 14:08 tonprince

Hi there! I'm experiencing this issue as well. When trying to deploy the functions on local emulator, the follow error is thrown:

⬢ functions: Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/augustogiavedoni/-----/-----/backend/functions/node_modules/camelcase/index.js from /Users/augustogiavedoni/-----/-----/backend/functions/node_modules/firebase-function-tools/lib/load.js not supported. Instead change the require of index.js in /Users/augustogiavedoni/-----/-----/backend/functions/node_modules/firebase-function-tools/lib/load.js to a dynamic import() which is available in all CommonJS modules.

Seems to me that the problem is that firebase-function-tools uses an outdated version of the camelcase package (currently using v5.3.1 and latest is 7.0.1).

augustogiavedoni avatar Dec 15 '22 15:12 augustogiavedoni