Home > database >  Firebase Accessing non-existent property 'db' of module exports inside circular dependency
Firebase Accessing non-existent property 'db' of module exports inside circular dependency

Time:08-18

I'm using Firebase with Node.js, there's multiple modules besides index.js and most of my modules needs to access admin and db. Accessing admin and db like this;

admin.js

const admin = require('firebase-admin');

admin.initializeApp();

const db = admin.firestore();

module.exports = { admin, db };

index.js

const { admin, db } = require('./admin');

I wasn't getting errors while I was using node 12 but after upgraded to node 16, started to get this error;

(node:1) Warning: Accessing non-existent property 'db' of module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created)

Throwing this error every time any function requested but my application works well. It's accessing db without any problem

CodePudding user response:

As mentioned by Arif :

This issue was because of some of old functions were passing 'db' and 'fv' like this; exports.userProfile = function(data, context, db, fv) and he changed this module's usage to same as index.js and called them at top of the module. Circular dependency issue is passing required parameters to another module from the called module instead of the main one.

As mentioned in the thread this issue sometimes could be because Newer NodeJS versions no longer allow circular dependencies.

Eg - There are two files - FileA.js, FileB.js

Where FileA.js has

const FileB = require("FileB");

and FileB.js has

const FileA = require("FileA");

After removing one of these circular dependencies by modifying either FileA.js or FileB.js.

If issue still persist try using command : npm update

  • Related