Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting: Error: Cannot find module '@firebase/component' on 8.6.0 #714

Closed
cgarg opened this issue Dec 6, 2019 · 32 comments
Closed

Getting: Error: Cannot find module '@firebase/component' on 8.6.0 #714

cgarg opened this issue Dec 6, 2019 · 32 comments

Comments

@cgarg
Copy link

cgarg commented Dec 6, 2019

After moving to 8.8.0 and reverting back to 8.6.0 started getting the following error:

Error: Cannot find module '@firebase/component'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.Module._load (internal/modules/cjs/loader.js:497:25)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/opt/deployment/production/longwalks_666/node_modules/@firebase/database/dist/index.node.cjs.js:9:17)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)

NPM verstion: 6.4.1
Node Version: 10.14.2

Have tried npm uninstall and reinstall removing the lock file.

@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@cgarg
Copy link
Author

cgarg commented Dec 6, 2019

worked after adding @firebase/component as dependency

@hariprasadiit
Copy link

facing the same issue

@antonvovchenko
Copy link

We also started getting this issue 2-3 hours ago. And we use latest 8.8.0 version. So seems this problem thrown by some dependency.

@hiranya911
Copy link
Contributor

Seems to be caused by the JS SDK release that has gone out yesterday. @Feiyang1 @hsubox76 do you have any ideas?

@parkerself22
Copy link

parkerself22 commented Dec 6, 2019

Was going to file this issue last night but was busy fighting errors in production servers caused by this. The main firebase sdk published a new release last night, and because the dependency for @firebase/database in firebase-admin is not pinned, it installed the latest release version of @firebase/database in our CI process.

Think the quick fix for this would be if you guys just release a new version with all @firebase/* dependencies pinned to known working ranges. I've patched our apps using yarn resolutions for the moment, @firebase/database v5.4.0 seems to solve the problem for now

@hiranya911
Copy link
Contributor

Fix underway at firebase/firebase-js-sdk#2416

@hiranya911
Copy link
Contributor

For those who are looking for an immediate workaround: https://twitter.com/plane1113/status/1203009025232654336

@parkerself22
Copy link

The fix of manually installing @firebase/component doesn't seem to work for firebase-admin, we tried that and ran into this:

Error: TypeError: instance.INTERNAL.registerComponent is not a function: TypeError: instance.INTERNAL.registerComponent is not a function
   at registerDatabase (/app/node_modules/@firebase/database/dist/index.node.cjs.js:15165:39)
   at Object.<anonymous> (/app/node_modules/@firebase/database/dist/index.node.cjs.js:15196: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 Function.<anonymous> (/app/node_modules/@sentry/node/dist/integrations/console.js:40:47)
   at Function._load (/app/node_modules/@sentry/node/dist/integrations/http.js:63:47)
   at Module.require (internal/modules/cjs/loader.js:692:17)
   at require (internal/modules/cjs/helpers.js:25:18)
   at DatabaseService.getDatabase (/app/node_modules/firebase-admin/lib/database/database.js:64:24)
   at FirebaseApp.database (/app/node_modules/firebase-admin/lib/firebase-app.js:231:24)

@Feiyang1
Copy link
Member

Feiyang1 commented Dec 6, 2019

@parkerself22 Do you have @firebase/app in your project? If yes, you need to upgrade it to the latest.

@parkerself22
Copy link

@Feiyang1 no we do not, the only firebase dependency we have in package.json is firebase-admin@8.8.0

@Feiyang1
Copy link
Member

Feiyang1 commented Dec 6, 2019

Can you share your package.json? If you are able to inspect your node_modules folder, do you see node_modules/@firebase/app ?

@parkerself22
Copy link

@Feiyang1 my apologies, looks like we actually do. I was not aware of the geofirestore dependency and it looks like we aren't still using it so I'm going to remove that and try to see if the fix of adding @firebase/component works

$ yarn why @firebase/app
yarn why v1.19.1
[1/4] 🤔  Why do we have the module "@firebase/app"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@firebase/app@0.4.17"
info Reasons this module exists
   - "geofirestore#firebase" depends on it
   - Hoisted from "geofirestore#firebase#@firebase#app"
info Disk size without dependencies: "448KB"
info Disk size with unique dependencies: "1.32MB"
info Disk size with transitive dependencies: "1.32MB"
info Number of shared dependencies: 6
✨  Done in 1.70s.

@parkerself22
Copy link

Though now it looks like the release went through, so I'll try that first. Thanks for quickly resolving this 👍 @Feiyang1 @hiranya911

In terms of preventing this in the future, would you guys consider pinning the @firebase dependencies for this repo? Seems like the possibility of this occurring again is still there because the firebase-admin release cycle does not seem to be synchronized with the rest of the firebase sdk (unless i'm missing something obvious).

@hiranya911
Copy link
Contributor

I don't think we want to pin the dependency versions. We want developers to be able to get the latest dependency versions whenever possible. I'd rather have some tests in the JS SDK to detect this sort of issues before releases. Also I don't think pinning dependency versions is a reliable solution -- since we can only pin our immediate dependencies, where each of them can have transitive dependencies declared with wildcards.

@parkerself22
Copy link

@hiranya911

You could pin the @firebase/database dependency and then run Renovate to keep this repo synced with the JS sdk. The rest of the @firebase packages have their @firebase dependencies pinned, common practice in a monorepo. Since this package isn't included in the monorepo I'm assuming none of the @firebase packages have tests to ensure they dont break firebase-admin. Renovate submitting PR's for @firebase updates ensures that no contracts are broken, and would still allow users to get the latest dependency versions if they haven't pinned their firebase-admin dependency.

From the perspective of just this library, you clearly have a volatile dependency with a broken release process in @firebase/database. This package has 550k+ weekly downloads, you have a responsibility to those users to keep this package stable and protect them from breakage in a package that they may not even be aware they are dependent on. Not to mention the fact that your users are paying to use the core service (if not the sdk).

The other option would be to just integrate this package into the monorepo, I'll admit I haven't looked at the internals of this package much so I don't know if that is feasible. Is that an option? If all of firebase was a single package we wouldn't have been affected by this issue either.

Sorry for the rant, little worn out from dealing with this all afternoon. Our CI tests actually caught the issue, but we then hurried through the "install @firebase/component" fix which worked until we realized we had an old non-Google dependency pulling in @firebase/app, which didn't cause issues until run time. Fun stuff.

@hiranya911
Copy link
Contributor

@parkerself22 I'm not suggesting we don't do anything to prevent this sort of issues. It's just that I'm not convinced freezing the dependency versions is the right solution. At its face this solution sounds like we are declaring that the new JS SDK release artifacts are unreliable, and so let's work around it in the downstream projects by taking dependencies on older versions. I'd rather work with the JS SDK team to see if they can provide stronger and enforceable contracts for their release artifacts.

The other downside of pinning the versions is that it is only effective if we release firebase-admin every time the JS SDK releases an upstream dependency. Otherwise our users will be stuck on older dependency versions for long periods. This is not something we can commit to at the moment. Our release processes are semi-manual, and we simply don't have the manpower to keep our release cycles in-sync. In fact this is exactly why we currently declare our dependency versions with wildcards.

@parkerself22
Copy link

@hiranya911 I agree with the first point on working closer with the JS team being the easiest solution (For the sake of the argument I mostly wrote my suggestions from a naive perspective where the two packages weren't as connected as they are). And the release process being manual explains why my Renovate fix wouldn't work to keep deps up to date automatically.

Thanks for taking the time to reply to all my concerns, I hope I didn't come off as giving you too hard of a time, I do sincerely appreciate everything ya'll do and think all the Firebase js libraries are really well done.

@samoule007
Copy link

@Feiyang1 node_modules/@firebase/app does not exist for me...
this is my package.json :
{
"name": "firebasemessaging",
"version": "1.0.0",
"description": "",
"main": "fonction.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"firebase-admin": "^8.8.0",
"request": "^2.88.0"
}
}

@Feiyang1
Copy link
Member

@samoule007 What error do you have?

@samoule007
Copy link

@Feiyang1

TypeError: instance.INTERNAL.registerComponent is not a function
at registerDatabase (C:\Users\Sam\Documents_Bloc3_rattrapage\firebaseMessaging2\functions\node_modules@firebase\database\dist\index.node.cjs.js:15168:39)
at Object. (C:\Users\Sam\Documents_Bloc3_rattrapage\firebaseMessaging2\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] (C:\Users\Sam\Documents_Bloc3_rattrapage\firebaseMessaging2\functions\node_modules\firebase-admin\lib\firebase-namespace.js:282:38)

@Feiyang1
Copy link
Member

Feiyang1 commented Dec 18, 2019

That's weird. Can you delete the node_modules and the lock file, then reinstall and see if the error goes away for you?

The line that gives you error only executes if @firebase/app is present in your project. see https://github.com/firebase/firebase-js-sdk/blob/master/packages/database/index.node.ts#L149

@samoule007
Copy link

Thank you, I just solved the probleme ! @firebase/app was absent so I did : $ install firebase
in the project and it appears (with lot's of other (uselesses ?) things) and the error was gone.

@shaibt
Copy link

shaibt commented Dec 20, 2019

I found out why I was experiencing this dumbfounding error.

Clean install today (no node_modules and no package-lock.json) of new firebase-admin 8.9.0 results in error:

TypeError: instance.INTERNAL.registerComponent is not a function
    at registerDatabase (.../node_modules/@firebase/database/dist/index.node.cjs.js:15168:39)
    at Object.<anonymous> (..../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 DatabaseService.getDatabase (.../node_modules/firebase-admin/lib/database/database.js:64:24)

The code causing this is in this function: function registerDatabase(instance) in the firebase database module:

try {
    // If @firebase/app is not present, skip registering database.
    // It could happen when this package is used in firebase-admin which doesn't depend on @firebase/app.
    // Previously firebase-admin depends on @firebase/app, which causes version conflict on
    // @firebase/app when used together with the js sdk. More detail:
    // https://github.com/firebase/firebase-js-sdk/issues/1696#issuecomment-501546596
    var firebase = require('@firebase/app').default;
    registerDatabase(firebase);
}
catch (err) {
    // catch and ignore 'MODULE_NOT_FOUND' error in firebase-admin context
    // we can safely ignore this error because RTDB in firebase-admin works without @firebase/app
    if (err.code !== 'MODULE_NOT_FOUND') {
        throw err;
    }
}

Although @firebase/app is not a dependency in package.json and doesn't exist in the node_modules folder, this line var firebase = require('@firebase/app').default actually doesn't fail on MODULE_NOT_FOUND but assigns this value to firebase var:

{ __esModule: true,
  initializeApp: [Function: initializeApp],
  app: { [Function: app] App: [Function: FirebaseAppImpl] },
  apps: [Getter],
  Promise: [Function: Promise],
  SDK_VERSION: '5.11.0',
  INTERNAL: 
   { registerService: [Function: registerService],
     removeApp: [Function: removeApp],
     factories: {},
     useAsService: [Function: useAsService],
     createFirebaseNamespace: [Function: createFirebaseNamespace],
     extendNamespace: [Function: extendNamespace],
     createSubscribe: [Function: createSubscribe],
     ErrorFactory: [Function: ErrorFactory],
     deepExtend: [Function: deepExtend],
     node: 
      { localStorage: Storage {},
        sessionStorage: Storage {},
        XMLHttpRequest: [Function] } },
  default: [Circular] }

What I found out: my project folder that included the node_modules dependency folders is located within its parent project's folder. The parent project has its own node_modules directory and it did include a version of @firebase-app.
When '@firebase/app' was required, node didn't find the package in the project's node_modules but in its parent project's node_modules.

If the given module is not a core module, Node.js will then begin to search for a directory named, "node_modules". It will start in the current directory (relative to the currently-executing Javascript file in Node) and then work its way up the folder hierarchy, checking each level for a node_modules folder.

My project directory structure exists forever so I don't understand completely what change started producing this error - I assume its a recent code change in the firebase/database module - but separating the project to a truly clean dependency environment cleared this up.

@vongohren
Copy link

@shaibt thanks for this find!
@hiranya911 you have any comments on monorepos and yarn workspaces?
We have a web client and an api under the same packages. But this now crashes.
Has worked for a couple of years, up to now for some reason.

But this basically means that in a yarn workspace setting, this is not possible? Unless doing special handling with no hoisting or something?

@nickelas
Copy link

Thanks shaibt. If I rename the node_modules in the parent folder I get no errors. If not, I get:

TypeError: instance.INTERNAL.registerComponent is not a function at registerDatabase (/home/user/proj/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15320:39) at Object.<anonymous> (/home/user/proj/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15353:5) at Module._compile (internal/modules/cjs/loader.js:774:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10) at Module.load (internal/modules/cjs/loader.js:641:32) at Function.Module._load (internal/modules/cjs/loader.js:556:12) at Module.require (internal/modules/cjs/loader.js:681:19) at require (internal/modules/cjs/helpers.js:16:16) at FirebaseNamespace.get [as database] (/home/user/proj/functions/node_modules/firebase-admin/lib/firebase-namespace.js:282:38) at makeProxiedDatabase (/home/user/.nvm/versions/node/v12.4.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:402:31)
Seems kinda crazy?

@hsubox76
Copy link

I'm not sure of your exact setup, but you shouldn't have to do anything special as long as the version of firebase, and therefore @firebase/app (which comes in as a dependency of firebase), in your parent directory is the most recent.

The most likely cause of this kind of error, where you have

  • a parent and a subdirectory that both have node_modules/
  • only the parent dir contains @firebase/app
  • the subdirectory contains firebase-admin:

is that the parent dir is depending on an older version of firebase. The firebase package should be at least version 7.5.2 or later to avoid this error. The corresponding version of @firebase/app is 0.4.26 if you want to check it specifically.

A reinstall won't work if you have locked your version of firebase to an older version in your parent package.json.

@nickelas
Copy link

Thank you, updating firebase in the parent dir solved it.
Just odd that since the two projects are separate they still affect each other?

@taykcrane
Copy link

taykcrane commented Sep 19, 2020

@hsubox76 Hi Christina - Lots of googling got me here. I'm getting the error documented here when running firebase deploy: firebase/firebase-tools#1989

TypeError: instance.registerVersion is not a function

This is what my package.json looks like

  "@firebase/app": "^0.4.26",
    "all": "^0.0.0",
    "firebase": "7.5.2",
    "firebase-tools": "^7.6.0",
    "firebaseui": "^3.6.1",

So I'm using 7.5.2, but am still getting this error. I notice that if I upgrade @firebase/app to the latest version, my app breaks due to using another library (https://github.com/tylermcginnis/re-base/).

Will be really difficult to debug why that library is breaking, so hoping to find a solution around this instance.registerVersion error.

Any advice?

@hsubox76
Copy link

  1. If you're not using firebase-admin this issue should be in https://github.com/firebase/firebase-js-sdk so if you have any further questions after this, please open an issue there.

  2. You shouldn't be directly installing @firebase/app. The correct version will be installed as a dependency of firebase. In many cases, similar errors have been fixed by deleting node_modules, removing yarn.lock or package-lock.json and reinstalling.

If you're still having problems, open an issue in https://github.com/firebase/firebase-js-sdk if you are definitely using firebase and not firebase-admin.

@Stas-Buzunko
Copy link

@hsubox76
"I'm not sure of your exact setup, but you shouldn't have to do anything special as long as the version of firebase, and therefore @firebase/app (which comes in as a dependency of firebase),*in your parent directory is the most recent."

wtf. why updating firebase-js-sdk affects firebase-admin??

I've faced the same problem with latest
"firebase-admin": "^9.4.2",
"firebase-functions": "^3.13.0"

and got this error. after updating firebase-js-sdk in parent folder it started working. why does firebase-admin/functions even check anything in parent folder's node_modules???

@jomendez
Copy link

In my case, I already had @firebase/app as part of firebase. I also have node 12 installed with Win 10

npm ls @firebase/app
functions@ C:\Users\me\source\repos\admin\functions
`-- firebase@5.2.4
  `-- @firebase/app@0.6.13

I fixed the issue by updating the firebase dependencies to the latest.

npm i --save firebase@latest firebase-admin@latest firebase-functions@latest

From my package.json:

"firebase": "^8.2.4",
  "firebase-admin": "^9.4.2",
  "firebase-functions": "^3.13.1",

Note: Always update firebase-tool to the latest:

npm i -g firebase-tools@lates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests