Installed firebase-admin using instructions here: https://www.npmjs.com/package/firebase-admin
Added firebase-admin to a module as instructed using:
var admin = require('firebase-admin');
in a module in a loopback node application. Application fails to start with the following error:
/Users/simon/Projects/APPICS/src/appics-backend/node_modules/firebase-admin/lib/utils/error.js:65
FirebaseError.prototype.toJSON = function () {
^
TypeError: Cannot assign to read only property 'toJSON' of object 'Error'
at /Users/abcdefg/Projects/APPICS/src/appics-backend/node_modules/firebase-admin/lib/utils/error.js:65:36
at Object.<anonymous> (/Users/simon/Projects/APPICS/src/appics-backend/node_modules/firebase-admin/lib/utils/error.js:72:2)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/abcdefg/Projects/APPICS/src/appics-backend/node_modules/firebase-admin/lib/firebase-namespace.js:21:15)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
Waiting for the debugger to disconnect...
Process finished with exit code 1
What happened? How can we make the problem occur?
This could be a description, log/console output, etc.
'use strict';
let admin = require("firebase-admin");
Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.
Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.
What happens if you try this without loopback?
Sorry, that does not compute. This is a loopback application (basically it's a express application). I can't just run the car without the motor.
Try it without loopback to see if it's a loopback-specific issue.
Alright, so I tried this simply (in an extra file 'foo.js')
'use strict';
let admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'https://foobar-push.firebaseio.com'
});
And I got no exception when calling
node ./foo.js
So far we have only received this one report about this problem. Since the problem appears to be specific to the Loopback environment, I think we need somebody from that project to take a look. If somebody thinks this is something that can be fixed in firebase-admin, please provide some details on the diagnosis and the fix, so we can follow up.
I am also seeing this error. Not a loopback application, just a regular babel and webpack application. Using Latest firebase-admin.
I also have this issue, it appears that it's linked with the usage of 'use strict' mode. I found some info on this mozzila dev network link.
Can strict mode be used alongside firebase admin?
Hey @abdurahmanadilovic. Do you have a repro for this issue? Ideally something that just uses TypeScript and no other frameworks? The original reporter of this issue could only repro the problem on Loopback.
I used this command to figure out where toJSON is defined as a read only property on Error objects
grep -r 'Object.defineProperty(Error.*' .
````
It was in my application code and not in any package. I just added `writable: true` to `Object.assignProperty` call and that fixed the issue. This is the code after modification:
Object.defineProperty(Error.prototype, 'toJSON', {
value() {
const alt = {};
Object.getOwnPropertyNames(this).forEach(function (key) {
alt[key] = this[key];
}, this);
return alt;
},
configurable: true,
writable: true
});
```
@JuergenSimon, @reactor81 can you please run the grep command and check where is toJSON defined as a read only property?
Most helpful comment
I used this command to figure out where
toJSONis defined as a read only property onErrorobjectsObject.defineProperty(Error.prototype, 'toJSON', {
value() {
const alt = {};
},
configurable: true,
writable: true
});
```
@JuergenSimon, @reactor81 can you please run the grep command and check where is
toJSONdefined as a read only property?