Home > database >  Having a problem with a MIME error, I'm starting with typescript
Having a problem with a MIME error, I'm starting with typescript

Time:04-18

I am translating a code from javascript to typescript and everytime i try to run it to see how it goes it shows these following errors.

indexjuego.html:20 Uncaught ReferenceError: mark is not defined at HTMLButtonElement.onclick (indexjuego.html:20:78)

Refused to execute script from 'http://127.0.0.1:5500/js.ts' because its MIME type ('video/mp2t') is not executable.

The code used to work perfectly before trying to use typescript so i know that the function mark is properly written.

I tried to look into mime type and what it is but it is still unclear

This is the part on the html code where I try to call the function mark

<div >   

        <button id="id1" style="margin: 17px;" onclick="mark(this.id)"  >  </button>
        <button id="id2" style="margin: 10px;" onclick="mark(this.id)"  >  </button>
        <button id="id3" style="margin: 10px;" onclick="mark(this.id)"  >  </button><br>
        <button id="id4" style="margin: 17px;" onclick="mark(this.id)"  >  </button>
        <button id="id5" style="margin: 10px;" onclick="mark(this.id)"  >  </button>
        <button id="id6" style="margin: 10px;" onclick="mark(this.id)"  >  </button><br> 
        <button id="id7" style="margin: 17px;" onclick="mark(this.id)"  >  </button>
        <button id="id8" style="margin: 10px;" onclick="mark(this.id)"  >  </button>
        <button id="id9" style="margin: 10px;" onclick="mark(this.id)"  >  </button>
        
    </div>

and this is the function mark

function mark(id) {
if (turn % 2 == 1) {
    console.log("asdas")
    document.getElementById(id).style.backgroundImage = "url('cruz.webp')";

} else if (turn % 2 == 0) {
    document.getElementById(id).style.backgroundImage = "url('circulo.webp')";

}

turno();
prueba();
cambiaturn();
winner(fin, finemp);
block(id);

}

The code is a tic tac toe game

CodePudding user response:

Seems like you're using the live server extension to run the code, if so, *.ts files won't be executed, because you have to covert then to javascript first, the browser understands only javascript

About MIME type, it is a convention for file extensions, per example .pdf is application/pdf but I don't think that it has something to do with your problem

here is a nice tutorial on how compile typescript to javascript, hope it helps

  • Related