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

155
Visualizações
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
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