Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: rtdb.initStandalone is not a function

I'm pretty new to both Node and Firebase, but can't seem to find this error online.

I get the following error when I try to load Firebase Database through Firebase Admin:

TypeError: rtdb.initStandalone is not a function DatabaseService../node_modules/firebase-admin/lib/database/database.js.DatabaseService.getDatabase node_modules/firebase-admin/lib/database/database.js:62

    var db = this.INTERNAL.databases[dbUrl];
    if (typeof db === 'undefined') {
        var rtdb = require('@firebase/database');
        db = rtdb.initStandalone(this.appInternal, dbUrl).instance;
        this.INTERNAL.databases[dbUrl] = db;
    }
    return db;

Node Module Versions: [email protected] @firebase/[email protected] @firebase/[email protected]

like image 245
Julian Quirke Avatar asked Jun 18 '26 02:06

Julian Quirke


1 Answers

In case anyone has the same issue I did:

@firebase/database/package.json:

"main": "dist/cjs/index.node.js",
"browser": "dist/cjs/index.js",
"module": "dist/esm/index.js",

initStandalone() is in dist/cjs/index.node.js but not dist/esm/index.js because it's only used serverside, not in the browser.

If you use webpack to bundle your code, even with target: 'node', it will prefer "module" over "main" and use the file intended for the browser.

The solution for me was to set resolve.mainFields to ["main", "module"] in webpack config.

PS. I'm using webpack to prepare my code for upload to AWS Lambda. If I don't use it I have to upload the entire node_modules folder which is huge and often causes timeouts on upload. I only need 10% of the code that's in there. If anyone knows of a better solution I'm keen to hear it.

like image 164
Jake Avatar answered Jun 20 '26 17:06

Jake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!