Skip to content

Unsupported import.meta methods to not replaced since v5.99 #19514

@chenjiahan

Description

@chenjiahan

Bug report

Unsupported import.meta methods to not replaced since v5.99.

Minimal example

  • Source code:
function main() {
    if (!import.meta.webpackHot) {
        return;
    }
    if (import.meta.webpackHot.status() !== 'idle') {
        console.log('idle');
    }
}

main();
  • webpack.config.mjs:
export default {
  mode: "development",
  devtool: false,
};
  • Output (5.97):
/******/ (() => { // webpackBootstrap
/*!**********************!*\
  !*** ./src/index.js ***!
  \**********************/
function main() {
    if (true) {
        return;
    }
    if (/* unsupported import.meta.webpackHot */ undefined.status() !== 'idle') {
        console.log('idle');
    }
}

main();

/******/ })()
;
  • Output (5.99.8):
/******/ (() => { // webpackBootstrap
/*!**********************!*\
  !*** ./src/index.js ***!
  \**********************/
function main() {
    if (true) {
        return;
    }
    if (import.meta.webpackHot.status() !== 'idle') {
        console.log('idle');
    }
}

main();

/******/ })()
;

This results in a "Uncaught SyntaxError: Cannot use 'import.meta' outside a module" runtime error

Reproduction

Other relevant information

webpack version: 5.99.8
Node.js version: 22
Operating System: macOS
Additional tools: none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions