Skip to content

LESS 4.6.2 causing build error #4423

Closed

Description

@isgeoffrey

To reproduce:
npm i with LESS set to ^4.5.1 or 4.6.2
running build with webpack

Current behavior:
webpack unable to build frontend applicaiton due to the following error
Module not found: Error: Can't resolve 'module' in 'C:\Users\xxx\git\xxx\node_modules\less\lib\less-node'

Expected behavior:
webpack builds normally

Environment information:

  • less version: 4.6.2
  • nodejs version: v24.0.0
  • operating system: windows & linux debian (when building in server)
  • webpack: 5.64.6

Able to resolve when locking LESS to 4.5.1 in package.json

Activity

  1. lincolnkjy commented on Mar 11, 2026

    @lincolnkjy

    metoo,i use vite. less version: ^4.1.0. error is "Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:"

  2. xbzhs commented on Mar 11, 2026

    @xbzhs

    metoo

  3. adityawrdhn commented on Mar 11, 2026

    @adityawrdhn

    me too

  4. oliver34 commented on Mar 11, 2026

    @oliver34

    me too

  5. Cygra commented on Mar 11, 2026

    @Cygra

    Yes, had to lock the version to 4.5.1.

    related: #4411

  6. Heiyanqiang commented on Mar 11, 2026

    @Heiyanqiang

    metoo

  7. alexander-akait commented on Mar 11, 2026

    @alexander-akait

    Because using module.exports = require('./lib/less-node/index.js').default; is a breaking change, before this package was in commonjs, now it is ECMA modules, not sure why it was under the minor, also adding exports is a breaking change too

  8. bressler95tops commented on Mar 11, 2026

    @bressler95tops

    Exactly the same thing when using 4.6+ with invenioRDM as it uses webpack under the hood. I believe the change in 4.6 that migrated to ESM is what broke it. I'll try to lock my dependencies to 4.5.1 in the mean time, but it seems odd that backwards compatibility was not considered. I'm sure there are other software configurations that have the same dependency.

  9. alexander-akait commented on Mar 11, 2026

    @alexander-akait

    Please update to https://github.com/webpack/less-loader/releases/tag/v12.3.2, anyway it is a breaking change and should be in the major release, not minor

  10. matthew-dean commented on Mar 11, 2026

    @matthew-dean
    Member

    My fault! Let me try to address right away. It was not intended to be a breaking change. I added tests for both ESM and CJS imports but maybe I missed some of these patterns?

  11. alexander-akait commented on Mar 11, 2026

    @alexander-akait

    @matthew-dean When you have dynamic require on Nodejs and run it, you will execute this line: module.exports = require('./lib/less-node/index.js').default;, but less-node/index.js code is ECMA modules, so it will not work, you should never doing such things like checking Node.js version and loading different version of a package it has a lot of shadow problems - like problems with caches, problems with memory leaking, problems with dynamic loading

  12. matthew-dean commented on Mar 11, 2026

    @matthew-dean
    Member

    @alexander-akait That's generally not true on modern Node.

    Current Node docs explicitly say require() can load ECMAScript modules from CommonJS as long as the ESM graph is synchronous, meaning no top-level await. Node also documents support for loading ES modules using require(), with a flag to disable it if needed.

    It's also not true that there will inevitably be issue with caches and memory leaking.

    But, that said, obviously there still is a loading problem, which I will address today.

  13. alexander-akait commented on Mar 11, 2026

    @alexander-akait

    Current Node docs explicitly say require() can load ECMAScript modules from CommonJS as long as the ESM graph is synchronous, meaning no top-level await. Node also documents support for loading ES modules using require(), with a flag to disable it if needed.

    if you have dynamic require in async function it will not work, and for some repos it can be disabled (with a flag to disable it if needed), so it is literally a breaking change, because before it works without any problems

    It's also not true that there will inevitably be issue with caches and memory leaking.

    No, if I will use import at the top of file I will use export from your package.json, but when in code I can use createRequire, but because your loading code based on Node.js version I will get ECMA modules instead commonjs modules, and so I will have two modules in memory (caches problems and shadow loading), do I need provide more information to understand why this idea is bad?

  14. 3 remaining items

  15. alexander-akait commented on Mar 11, 2026

    @alexander-akait

    @matthew-dean works fine with dynamic import and require, like it was before, tested for less-loader

  16. matthew-dean commented on Mar 11, 2026

    @matthew-dean
    Member

    @alexander-akait Thanks! Sorry for the inconvenience. Has more test coverage around each scenario now with a specific webpack test harness.

    I'm going to go ahead and publish, but the changes are here if anyone finds something that looks problematic.

  17. matthew-dean commented on Mar 11, 2026

    @matthew-dean
    Member

    Leaving open in case someone else experiences any issues. Will close later.

  18. xunge0613 commented on Mar 12, 2026

    @xunge0613

    node v14.21.3

    me too, before build error, my config was,

    "less": "^4.1.3",
    "less-loader": "^11.0.0",
    

    and then I tried using fixed less version and the build is success

    "less": "4.3.0",
    "less-loader": "^11.0.0",
    

    when build error ,these warning logs appeared :

    (node:563) UnhandledPromiseRejectionWarning: TypeError: implementation.logger.addListener is not a function at Object.lessLoader(/.../node_modules/less-loader/dist/index.js:51:25)
    at LOADER_EXECUTION (.../node_modules/loader-runner/lib/LoaderRunner.js:195:14)
    at runSyncOrAsync (.../node_modules/loader-runner/lib/LoaderRunner.js:196:5)
    08:45:15 at iterateNormalLoaders (/.../node_modules/loader-runner/lib/LoaderRunner.js:258:2)
    08:45:15 at processResourceCallback (/.../node_modules/loader-runner/lib/LoaderRunner.js:282:5)
    08:45:15 at Object.processResource (/.../node_modules/webpack/lib/NormalModule.js:1116:14)
    08:45:15 at runMicrotasks ()
    08:45:15 at processTicksAndRejections (internal/process/task_queues.js:95:5)
    08:45:15 at runNextTicks (internal/process/task_queues.js:64:3)
    08:45:15 at processImmediate (internal/timers.js:437:9)
    08:45:15 (Use node --trace-warnings ... to show where the warning was created)
    08:45:15 (node:563) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

  19. alexander-akait commented on Mar 12, 2026

    @alexander-akait

    @xunge0613 Please update less-loader to the latest version

  20. matthew-dean commented on Mar 12, 2026

    @matthew-dean
    Member

    @xunge0613 Still an issue with the latest Less version? 4.6.3?

  21. matthew-dean commented on Mar 12, 2026

    @matthew-dean
    Member

    Closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions