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.

Cannot read property 'insertBefore' of null

See original GitHub issue

Looks like this is occurring in the createNewHosts function call.

function createNewHosts(cmps) {
    var components = cmps.map(function (componentNode) {
        var newNode = document.createElement(componentNode.tagName);
        // display none
        var currentDisplay = newNode.style.display;
        newNode.style.display = 'none';
        var parentNode = componentNode.parentNode;
        parentNode.insertBefore(newNode, componentNode); //Problem hits here

         //Potential fix simple but could avoid this in future. 
         if ( !!componentNode.parentNode ) {
              var parentNode = componentNode.parentNode;
              parentNode.insertBefore(newNode, componentNode);
         }

        return { currentDisplay: currentDisplay, newNode: newNode };
    });

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Minh-Vancommented, Jun 2, 2018

I got same problem. Any update for this issue ?

0reactions
montella1507commented, Jun 12, 2018

The problem seems to be here in Helpers.js

var parentNode = componentNode.parentNode; <<< componentNode is “app-component” selector, parentNode is “NULL”… however… parent node in DOM is <body>
var currentDisplay = newNode.style.display; newNode.style.display = ‘none’; parentNode.insertBefore(newNode, componentNode);

maybe it is because of angular 6 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'insertBefore' of null
I happened to get the error just like you, and I guess the error might be Cannot read property 'insertBefore' of null ....
Read more >
"TypeError: Cannot read property 'insertBefore' of null" #16
I'm still getting the `` error with the latest version of this. I did notice most of the other instances of this error...
Read more >
Uncaught TypeError: Cannot read property 'insertBefore' of ...
However, it doesn't work and I get this error in the console every time: “Uncaught TypeError: Cannot read property 'insertBefore' of null”.
Read more >
Error on Cannot read properties of null (reading insertBefore)
Hi Man. Which browser are you using? We found that some Chrome extensions are interfering with the Mendix client and cause this error....
Read more >
Cannot read property 'insertBefore' of null at app.js:13 (Example)
Uncaught TypeError : Cannot read property 'insertBefore' of null at app.js:13 ... This is driving me insane, can't for the life figure out...
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