javascriptstackblitz

Identifier 'runTimers' has already been declared


The program works perfectly on Visual Studio Code, but not sure Stackblitz. (I really need to use Stackblitz.)

The error message:

Identifier 'runTimers' has already been declared

The url Stackblitz is here => https://stackblitz.com/edit/web-platform-yaoyey?file=index.html

Thank you for your help.


Solution

  • As per your codebase in index.html, you have two script tags as follow:

    <script src="btc.js"></script>
    <script src="eth.js"></script>
    

    Due to this, both btc.js and eth.js is imported and processed.

    In btc.js, you have following at Line 25

    let runTimers = setInterval(
    

    And in eth.js, you have following at Line 25

    let runTimers = setInterval(
    

    So, the runTimer is declared twice, i.e. first btc.js is imported in index.html and the first runTimer variable is declared and cleared and after that eth.js is imported in index.html and it tries to create runTimer, which causes the error.

    To fix this, simply rename the variables, which would avoid conflict and fix the issue.