Skip to content

12.3.2 breaking change for CJS consumers — await import('less') requires --experimental-vm-modules in Jest #584

@gabrielsh2

Description

@gabrielsh2

Have you used AI?

Yes

Bug Description

less-loader 12.3.2 changed the way less is imported internally from:

const less = require('less');

to:

const less = await import('less');

When the loader is executed via Node.js require(), as Jest does during test runs,
the dynamic ESM import requires the --experimental-vm-modules flag to work.

From what I've checked, these changes were introduced in this PR #578 and it was necessary because of the following less issue less/less.js#4423

The less change was patched in 4.6.3 and then I was able to keep using jest without the ESM flag using 4.6.4 and fixing less-loader into 12.3.1

Link to Minimal Reproduction and step to reproduce

  1. Use less-loader 12.3.2 in a CJS project
  2. Run Jest tests that involve webpack compilation with the less-loader
  3. Observe tests failing without --experimental-vm-modules

Expected Behavior

A change that requires consumers to add Node.js experimental flags should be documented as a breaking change, or released as a major version bump.

Actual Behavior

Released as a patch (12.3.1 → 12.3.2), causing unexpected test failures in CI
for projects that don't use --experimental-vm-modules.

Environment

System:
    OS: macOS 26.3.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 82.13 MB / 18.00 GB
  Binaries:
    Node: 20.19.2 - /Users/i752731/.nvm/versions/node/v20.19.2/bin/node
    Yarn: 1.22.22 - /Users/i752731/.nvm/versions/node/v20.19.2/bin/yarn
    npm: 10.8.2 - /Users/i752731/.nvm/versions/node/v20.19.2/bin/npm
  Browsers:
    Chrome: 146.0.7680.178
    Firefox: 145.0
    Safari: 26.3.1
  Packages:
    css-loader: ^7.0.0 => 7.1.4 
    html-webpack-plugin: ^5.5.0 => 5.6.6 
    inline-environment-variables-webpack-plugin: ^1.2.1 => 1.2.1 
    less-loader: ^12.3.2 => 12.3.2 
    style-loader: ^4.0.0 => 4.0.0 
    terser-webpack-plugin: ^5.3.14 => 5.4.0 
    webpack: ^5.88.2 => 5.106.0 
    webpack-cli: ^7.0.2 => 7.0.2 
    webpack-merge: ^6.0.0 => 6.0.1 
    webpack-sources: ^3.2.3 => 3.3.4 
    webpack-subresource-integrity: ^5.1.0 => 5.1.0

Is this a regression?

None

Last Working Version

No response

Additional Context

No response

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