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

170
Visualizações
running page specific setup functions while using web pack - "does not provide an export named 'init_home'"

I have a structure like this, with js files i have bundled with web pack. (all simplified for readability)

home.html

main.bundle.js

home.html

<html>
   <head>
      <script type="module" src="main.bundle.js"></script>
   </head>
   <body>
   </body>
</html>

inside the src js it would look like this

src.js

import {some-imports} from this.js

window.addEventListner("load", ()=>{ 
    # page load code for ALL pages 
})

function init_home(){
    #home page init code
}

function init_contact(){
    #contact page init code
}

export {init_home, init_contact}

how is the prefered way to call these init functions on each page?

I have tied adding this script tag at the bottom of each page with no luck

<script type="module">
    import {init_home} from './static/deploy/main.bundle.js'
    init_home()
</script>

I keep getting errors like this.

The requested module './static/deploy/main.bundle.js' does not provide an export named 'init_home'

also is it correct that i am trying to import the same js file twice?

webpack.config.js (just incase)

const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const path = require('path');


module.exports = {
  plugins: [
    new CleanWebpackPlugin()
  ],
  entry: {
    main: path.resolve(__dirname, './js/fire.js'),
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'deploy')
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
    ]
  },
}
about 4 years ago · Santiago Gelvez
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