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

144
Visualizações
importing ColorThief doesn't work and messes up code

I tried to import ColorThief into my code but I get an error saying

Uncaught SyntaxError: Cannot use import statement outside a module

I don't know what to do since I just copied the import statement on the ColorThief website, and I downloaded the node-module thing so the path is correct.

In addition I found out that the import statement causes another error. It causes my setBio function to be "declared but never read" but I used it in my HTML file like this:

<button onClick=setBio()>Search</button>

The error disappears and everything works (all the features I implemented before trying to implement a color thief feature) once I comment out the import statement.

Here's a condensed version of what's in my JS file:

import ColorThief from './node_modules/colorthief/dist/color-thief.mjs'

let setBio = async () =>
{
    let input = document.getElementById("input");
    let pokemon = input.value.toLowerCase();
    input.value = ""

    let display = document.getElementById("name");
    display.innerHTML = await getName(pokemon);

    let pic = document.getElementById("img");
    pic.src = await getPic(pokemon);
    setBGColor();
}

Any help would be appreciated. I am new so I apologize if it's something stupid

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