question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • 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");

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
abdurahmanadiloviccommented, 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?

0reactions
hiranya911commented, Apr 2, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot assign to read only property 'toJSON' of object Error ...
Simple GET request with server status code 4xx, 5xxx throw error Uncaught TypeError: Cannot assign to read only property 'toJSON' of object ......
Read more >
TypeError: Cannot assign to read only property - Stack Overflow
1 Answer 1 · something populates your array · for whatever reason, some or all properties of some or all of the objects...
Read more >
TypeError: Cannot assign to read only property '_msgid' #2 - IBM
I get an error from the debug log: TypeError: Cannot assign to read only property '_msgid' of Number 10 is a high number....
Read more >
TypeError: Attempted to assign to readonly property
In my code I was updating this JSON object, using the dot syntax (like data.name = 'Flavio' ) but I forgot to call...
Read more >
Cannot assign to read only property 'X' of object ... - Reddit
Hi everyone, I am currently encountering an issue within my LWC. It was working before, but now it is throwing an error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found