Skip to content

[experiments.lazyCompilation] import()ing asset modules will fail #19532

@uhyo

Description

@uhyo

Bug report

What is the current behavior?

With experiments.lazyCompilation enabled, import()ing an asset module will fail with the following error message:

hook.js:608 TypeError: Cannot read properties of undefined (reading 'call')
    at __webpack_require__ (bootstrap:22:1)
    at fn (hot module replacement:61:1)
    at __webpack_require__.t (create fake namespace object:10:1)
Relevant code from __webpack_require__
	// Execute the module function
	var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ };
	__webpack_require__.i.forEach(function(handler) { handler(execOptions); });
	module = execOptions.module;
	execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
//.                         ^^^^

If the current behavior is a bug, please provide the steps to reproduce.

Reproduction repository: https://github.com/uhyo/webpack-bug-repro

Revelant settings from webpack.config.js:

  module: {
    rules: [
      {
        test: /\.png$/,
        type: 'asset/resource',
      },
    ],
  },
  experiments: {
    lazyCompilation: {
      entries: false,
      imports: true,
    }
  }

Relevant code:

import(`./assets/illust.png`).then((module) => {
  console.log('Image loaded:', module.default);
  const img = document.createElement('img');
  img.src = module.default;
  document.body.appendChild(img);
}).catch((error) => {
  console.error('Error loading image:');
  console.error(error);
});

What is the expected behavior?

import()ing an asset module should succeed with lazyCompilation enabled.

Other relevant information:
webpack version: 5.99.8
Node.js version: 22.14.0
Operating System: Mac 0S
Additional tools:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions