Reputation: 1353
After updating to the newest firebase SDK and tools
npm install firebase-functions@latest firebase-admin@latest --save
npm install -g firebase-tools
I started getting the following error when trying to deploy my firebase functions:
TypeError: instance.INTERNAL.registerComponent is not a function
at registerDatabase (/Users/jr/projects/docavea/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15168:39)
at Object.<anonymous> (/Users/jr/projects/docavea/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15200:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at FirebaseNamespace.get [as database] (/Users/jr/projects/docavea/functions/node_modules/firebase-admin/lib/firebase-namespace.js:282:38)
I have found posts on https://github.com/firebase/firebase-admin-node/issues/714 and
https://github.com/firebase/firebase-admin-node/issues/717 and https://twitter.com/plane1113/status/1203009025232654336 that suggests various solutions for this problem, but none of them worked for me, except to include @firebase/app. Some suggested that this was cause by having @firebase/app somewhere in my project but when I ran
npm ls @firebase/app
I got
functions@ /Users/jr/projects/docavea/functions
└── (empty)
So my question is: What is @firebase/app and is it a problem to include it in my firebase functions package.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/src/index.js",
"dependencies": {
"@firebase/app": "^0.5.0",
"@sendgrid/mail": "^6.4.0",
"cors": "^2.8.5",
"firebase-admin": "^8.9.0",
"firebase-functions": "^3.3.0",
"lodash": "^4.17.15",
"mailchimp-api-v3": "^1.13.1"
},
"peerDependencies": {
"@google-cloud/firestore": "^3.3.2"
},
"engines": {
"node": "8"
},
"devDependencies": {
"tslint": "^5.20.1",
"typescript": "^3.7.4"
},
"private": true
}
Upvotes: 1
Views: 2829
Reputation: 1353
Based on @Christina Holland answer I investigated a bit further. When I ran npm ls @firebase/app
in my Angular folder (functions is a subfolder of that) I got:
└─┬ UNMET PEER DEPENDENCY [email protected]
└── @firebase/[email protected]
npm ERR! peer dep missing: firebase@>= 5.5.7 <7, required by @angular/[email protected]
I then updated @angular/fire to the newest version. It didn't change the @firebase/app version, but it removed the error:
└─┬ [email protected]
└── @firebase/[email protected]
After that I could remove @firebase/app from my a functions package.json and I could deploy without any errors.
I don't understand what happens here, but the problem is solved and maybe it can help some other developer with this problem.
Upvotes: 0
Reputation: 211
First, to answer the question @firebase/app
is a module that is part of the Firebase Web SDK (you get it by npm install firebase
) and never needs to be manually installed, and should not be installed at all for firebase-admin
.
So in a nutshell, here is what's going on with this error, in general: firebase-admin
has a dependency called @firebase/database
, which is shared with the Firebase Web SDK. A recent release of @firebase/database
had some changes that caused it to not work if used with an older version of @firebase/app
.
So basically, it should work if you have either (1) no @firebase/app
or (2) a current @firebase/app
. Your error sounds most likely to be an existing outdated @firebase/app
.
I know you said you don't seem to have @firebase/app
in your project but since it seems like the most likely cause, I'm wondering if you have it in a parent directory. (It's installed as part of the Firebase Web SDK, as in npm install firebase
.) Most firebase functions (if you use firebase init) are set up in a /functions
subdirectory of the main project repo, with its own package.json, and the rest of the project is one level up and has another package.json. And that looks like it might be your dir structure?
In that case, running npm ls
inside /functions
will turn up an empty result, but if you go up to the parent dir (that contains the other package.json), it will show up. Node will go up a level if it doesn't find a package at the current one. See if you can ensure both levels are clean from any @firebase/app
, delete both node_modules dirs, reinstall. If you do need it in the top level (for Firebase Web SDK), make sure it is upgraded the most current firebase
(7.6.1).
As a last resort, maybe check to see if firebase
is npm installed globally somehow.
If you definitely don't have @firebase/app
at any level of your project and it's still failing, this is a bug we should look into.
Sorry that's a lot of info! Hope that wasn't too much. TLDR: I think you do probably have @firebase/app in your project root dir? If not, please file an issue on Github.
Upvotes: 1