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

TypeError: Cannot assign to read only property 'toJSON' of object 'Error' #215

Closed
JuergenSimon opened this issue Feb 26, 2018 · 11 comments
Closed

Comments

@JuergenSimon
Copy link

JuergenSimon commented Feb 26, 2018

  • Operating System version: macos 10.12.6, Node 9.5.0
  • Firebase SDK version: 5.9.0
  • Library version: 4.10.1
  • Firebase Product: admin (auth, database, storage, etc)

[REQUIRED] Step 3: Describe the problem

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

Steps to reproduce:

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

Relevant Code:

'use strict';

let admin = require("firebase-admin");
@google-oss-bot
Copy link

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@google-oss-bot
Copy link

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@hiranya911
Copy link
Contributor

What happens if you try this without loopback?

@JuergenSimon
Copy link
Author

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.

@hiranya911
Copy link
Contributor

Try it without loopback to see if it's a loopback-specific issue.

@JuergenSimon
Copy link
Author

JuergenSimon commented Feb 27, 2018

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

@hiranya911
Copy link
Contributor

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.

@reactor81
Copy link

I am also seeing this error. Not a loopback application, just a regular babel and webpack application. Using Latest firebase-admin.

@abdurahmanadilovic
Copy link

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?

@hiranya911
Copy link
Contributor

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.

@abdurahmanadilovic
Copy link

abdurahmanadilovic commented Apr 3, 2019

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?

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

No branches or pull requests

5 participants