You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Reacted by dosubot, lincolnkjy, Lyman_gh, chiic, jy, GmPino, adityawrdhn, LAKSHMAN PRADEEP KALIDINDI, Brian Ressler, Theodoor van Donge and 1 more
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:"
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
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.
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?
@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
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.
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?
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)
Activity
lincolnkjy commentedon Mar 11, 2026
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:"
xbzhs commentedon Mar 11, 2026
metoo
adityawrdhn commentedon Mar 11, 2026
me too
oliver34 commentedon Mar 11, 2026
me too
Cygra commentedon Mar 11, 2026
Yes, had to lock the version to 4.5.1.
related: #4411
Heiyanqiang commentedon Mar 11, 2026
metoo
alexander-akait commentedon Mar 11, 2026
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 addingexportsis a breaking change toobressler95tops commentedon Mar 11, 2026
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.
alexander-akait commentedon Mar 11, 2026
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
matthew-dean commentedon Mar 11, 2026
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?
alexander-akait commentedon Mar 11, 2026
@matthew-dean When you have dynamic
requireon Nodejs and run it, you will execute this line:module.exports = require('./lib/less-node/index.js').default;, butless-node/index.jscode 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 loadingmatthew-dean commentedon Mar 11, 2026
@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.
alexander-akait commentedon Mar 11, 2026
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
No, if I will use
importat the top of file I will useexportfrom yourpackage.json, but when in code I can usecreateRequire, 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?3 remaining items
alexander-akait commentedon Mar 11, 2026
@matthew-dean works fine with dynamic
importandrequire, like it was before, tested forless-loadermatthew-dean commentedon Mar 11, 2026
@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.
fix: webpack browser build - use UMD dist/less.js, add CJS bundle (#4424
matthew-dean commentedon Mar 11, 2026
Leaving open in case someone else experiences any issues. Will close later.
xunge0613 commentedon Mar 12, 2026
node v14.21.3
me too, before build error, my config was,
and then I tried using fixed less version and the build is success
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)alexander-akait commentedon Mar 12, 2026
@xunge0613 Please update less-loader to the latest version
matthew-dean commentedon Mar 12, 2026
@xunge0613 Still an issue with the latest Less version? 4.6.3?
matthew-dean commentedon Mar 12, 2026
Closing as fixed.
Less 5 alpha.1: Jess-powered compiler preview (#4487)