5

With the following code:

const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()

exports.onTest = functions.https.onRequest(async (req, res) => {
  res.json({ msg: 'done' })
})

which comes exactly from the example docs, ... running firebase emulators:start from cli generates the following error:

 ⚠  TypeError: instance.registerVersion is not a function
    at registerDatabase (/Users/<path>/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15188:14)
    at Object.<anonymous> (/Users/<path>/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15200:5)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at FirebaseNamespace.get [as database] (/Users/tremendus/Development/kulanu/playground/kulanu-cloud/functions/node_modules/firebase-admin/lib/firebase-namespace.js:282:38)
⚠  We were unable to load your functions code. (see above)

Several other examples on SO and other sites call #initializeApp with initializeApp(functions.config().firebase) ... but this also throws the same error.

I'm using node 8 functions and node 8 locally and basic pacakage.json dependencies:

"dependencies": {
    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.3.0"
  }

UPDATE: although the command firebase emulators:start throws the above error, the functions work in shell:

MacPro:functions: firebase functions:shell
✔  functions: Emulator started at http://localhost:5000
>  function: apiOnSave
i  functions: Loaded functions: apiOnSave
firebase > apiOnSave()
Sent request to function.
firebase > >  function: apiOnSave

RESPONSE RECEIVED FROM FUNCTION: 200, {
  "msg": "done"
}

Doesn't anyone have suggestions on how to resolve this?

Tremendus Apps
  • 1,497
  • 12
  • 20
  • PS - this is the only function in my function library – Tremendus Apps Dec 17 '19 at 17:09
  • If you have updates or modification to your question, you can simply edit the question instead of adding a comment. – Doug Stevenson Dec 17 '19 at 17:09
  • If have clear reproduction steps that suggest there might be a bug in the Firebase CLI, please post an issue on the Firebase CLI GitHub. https://github.com/firebase/firebase-tools – Doug Stevenson Dec 17 '19 at 17:11
  • @DougStevenson - I can't reproduce it in a freshly initialized project ... that does work. But if I copy the firebase config files and functions folder from the fresh initialized folder to the project folder, I still get the error. the same also occurs if I re-init the project folder. Are there any other config files or a cache that might be affecting why it works in a fresh folder, but not in a freshly initialized existing folder? – Tremendus Apps Dec 17 '19 at 18:10

1 Answers1

2

Seems to be a bug in firebase@7.6.1. Going back to firebase@7.6.0 fixes it for me.

Direct Dependecy

Since for me, firebase is a direct dependency, this does the trick:

npm i -S firebase@7.6.0 --force

Indirect dependency

However in your case, it is an indirect dependency -- Try to find out which version your installation uses with:

npm list firebase

Try going back to a version of firebase-admin and firebase-functions that uses an earlier version of firebase.

Domi
  • 22,151
  • 15
  • 92
  • 122