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

405
Visualizações
npm webpack-mix - calling javascript function from a file

I am trying to access function defined in table.js file from index.html.
table.js

    let table;

    function set_table(table) {
      this.table = table;
      console.log("function called successfully");
    }
    
    export {set_table}; 


index.html

    <script src="table.js"></script>

    <script type="text/javascript">

      set_table("test");

    </script>

I'm using npm webpack mix to compile table.js and receiving the error Uncaught ReferenceError: set_table is not defined.

Please suggest the best way to access table.js function in index.html

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Module exports need to be set on window. So, just import set_table in script type="module" and then set it on window as window.set_table

    <script type="module">
          import { set_table } from "./table.js";
          window.set_table = set_table;
        </script>

See this answer https://stackoverflow.com/a/69083651/1109657

about 4 years ago · Juan Pablo Isaza Relatório
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