Error when calling appendChild(app.view) in Javascript file

48 views Asked by At

I have created a simple Javascript block of code in my HTML script, I am trying to load the newly created Pixi App but I get an error: "Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. at window.onload (index.html:18:26)"

Here's the block of code:

<script>
    window.onload = function() {

       let app = new PIXI.Application <HTMLCanvasElement> ({
            width: 800,
            height: 600,
            background: '#1099bb'
        });
        
       document.body.appendChild(app.view); //THIS IS THE ROOT OF THE ERROR
    }

</script>

I'm using PixiJS version 7.4.0 and the program runs fine when I do any other Javascript code like adding elements or changing innerText.

I have made sure PixiJS version and the PixiJS library version match.

1

There are 1 answers

0
Rayzel On

try this:

<script>
    window.onload = function() {

       let app = new PIXI.Application({
            width: 800,
            height: 600,
            backgroundColor: 0x1099bb
        });
        
       document.body.appendChild(app.view as HTMLElement); 
    }

</script>