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

163
Views
Injected Module not properly loaded when enabling Webpack HMR

I am working on a library, and then injecting it into a html document using Webpack. I need to enable HMR on the project. However, when I enable it, the library won't get loaded properly. Here is what I get from the console:

Library.init() is not a function.

and library gets loaded as an empty object whereas by turning HMR off, it gets loaded correctly.

Here is my Webpack configuration:

{ 
...baseConfigs,
entry: './src/index.ts',
output: {
        path: __dirname + '/dist',
        filename: `lib.js`,
        library: {
            name: 'Library',
            type: 'window',
        },
    },
    devServer: {
        contentBase: path.resolve(__dirname, 'dist'),
        publicPath: '/',
        port: 8000,
        open: true,
        hot: true,
    },
    plugins: [
        ...baseConfig.plugins,
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, 'demo', 'index.html'),
            inject: 'head',
        }),
        new webpack.HotModuleReplacementPlugin(),
    ],
}

and the entry point - index.ts - is like this:

import {main, subscribe} from './main' // Library's main functionality imported

export {
   init,
   subscribe,
}

if(module.hot){
   module.hot.accept('./index.ts')
}

Am I missing a piece of the puzzle?

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