Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
"Unexpected token 'export'" error in Chrome, "export declarations may only appear at top level of a module" in firefox

In my snake.html file, I included main.js in module type

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Snake</title>
    <link rel="icon" href="images/favicon.ico">
    <link rel="stylesheet" href="css/snake.css">

</head>
<body>
    <div id="gameBoard"></div>
    
    <script src="snake/main.js" type="module"></script>
</body>
</html>

In main.js, I imported some variables and functions from snake.js

import {speed, update as updateSnake, render as renderSnake} from "./snake.js";
updateSnake();

In snake.js, I imported a function from input.js

import {getDirection} from "./input.js";
export function update()
{
    const direction = getDirection();
    for(let i = 0; i < snakeBody.length; i++)
    {
        let segment = snakeBody[i];
        segment.x += direction.x;
        segment.y += direction.y;

    }
    console.log("Snake updated");
}

Lastly, in input.js I have an exported function named as getDirection

let direction = {x: 0, y: 0};
let lastDirection = {x: 0, y: 0};
export function getDirection()
{
    lastDirection = direction;
    return direction;
}

I did not write full code here in order to simplify the problem. When i open snake.html file in browser with live server, i got "Uncaught SyntaxError: Unexpected token 'export'" in Chrome. I searched through all results on google that i found, and no one worked. (also in getDirection function, it says "'getDirection' is declared but its value is never read." I really need help?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda