Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!