Skip to content

webpack 5 the page opens blank the first time when use lazy compilation #3204

@await-ovo

Description

@await-ovo

Bug report

When I try lazy compilation, I find that the first time I open the page is always blank.
Here is a simple repo to reproduce: https://github.com/await-ovo/webpack5-lazy

  1. git clone https://github.com/await-ovo/webpack5-lazy
  2. cd webpack5-lazy && yarn
  3. yarn dev

Then open localhost:8080/a.html, you can see that the page is empty:

image

This is my webpack config:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: {
    a: path.resolve('./src/a.js'),
    b: path.resolve('./src/b.js')
  },
  devtool: 'cheap-module-source-map',
  devServer: {
    dev: {
      writeToDisk: true,
    }
  },
  optimization: {
    runtimeChunk: true,
  },
  experiments: {
    lazyCompilation: true,
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'a.html',
      template: path.resolve('./index.html'),
      chunks:['a']
    }),
    new HtmlWebpackPlugin({
      filename: 'b.html',
      chunks:['b'],
      template: path.resolve('./index.html')
    })
  ]
}

What is the current behavior?
The page opens blank in the browser and must be refreshed manually

If the current behavior is a bug, please provide the steps to reproduce.
Reproduction steps are as described above

What is the expected behavior?
It should display content correctly.

Other relevant information:
Once the runtimeChunk is commented out, everything works fine.
If it's a bug, I'm happy to help fix it, but I need some guidance, thanks~
webpack version: 5.34
Node.js version: 14
Operating System: macos
Additional tools:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions