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: Right-hand side of 'instanceof' is not an object

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/zone.js

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Description

instanceof is not safe operation, so if you monkeypatch such substantial method as Object.prototype.toString, you have to use try…catch

πŸ”¬ Minimal Reproduction

https://stackblitz.com/...

πŸ”₯ Exception or Error

TypeError: Right-hand side of 'instanceof' is not an object

🌍 Your Environment

Angular Version:





Anything else relevant?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JiaLiPassioncommented, Aug 10, 2020

@rifler, I can reproduce the issue.

<html>
  <body>
    <script src="./node_modules/zone.js/dist/zone.js"></script>
    <script>
      window[Zone.__symbol__('ZoneAwarePromise')] = undefined;
      window[Zone.__symbol__('Promise')] = undefined;
      const obj = {};

      console.log('toString', obj.toString());
    </script>
  </body>
</html>

And about the fix, use try/catch will impact the performance and also swallow the error. So the recommend fix is

        Object.prototype.toString = function () {
            if (typeof Promise !== 'undefined' && this instanceof Promise) {
                return PROMISE_OBJECT_TO_STRING;
            }
            return originalObjectToString.call(this);
        };

could you update the PR? thanks!

1reaction
AndrewKushnircommented, Aug 10, 2020

Hi @rifler, thanks for providing additional information.

I’m adding @JiaLiPassion to this thread to get his opinion from the ZoneJS standpoint (he should also have an access to reopen PR #38350 once the root cause is identified).

Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: invalid 'instanceof' operand 'x' - JavaScript | MDN
The JavaScript exception "invalid 'instanceof' operand" occurs when the right-hand side operands of the instanceof operator isn't used withΒ ...
Read more >
How to fix "TypeError: Right-hand side of 'instanceof' is not ...
I tried to check the type of context whether it is an instance of Context, which is in another file, but node js...
Read more >
Right-hand side of 'instanceof' is not callable - Moralis Forum
I am getting a following error: TypeError: Right-hand side of 'instanceof' is not callable. My deps: "dependencies": { "moralis": "1.11.0", "next": "12.1.5"Β ...
Read more >
Error: Right-hand side of 'instanceof' is not callable | Vue Forums
Error: Right-hand side of 'instanceof' is not callable Β· 1. Share the code snippet of ListView component. Β· 2. Whether you have rendered...
Read more >
TypeError: Right-hand side of 'instanceof' is not an ... - Laracasts
If it has been updated, is should call a method called 'addItem', that will add the item to my editor. However, for some...
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