Skip to content

lessc CLI fails to start since 4.6.0: bin/lessc is extensionless under "type": "module" #4561

Open

Description

@tomhamming

I have an npm project that uses lessc to compile some less to CSS. I use gulp to do the build, and in my gulpfile.js I shell out to lessc:

npx lessc myFile.less myFile.css

With less 4.6.0 and above, I get an error:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for
.../node_modules/less/bin/lessc. Loading extensionless files is not supported
inside of "type":"module" package.json contexts.

Claude believes it's because of #4411. I'm pasting its issue draft below with more details.

lessc CLI fails to start since 4.6.0: bin/lessc is extensionless under "type": "module"

To reproduce:

mkdir repro && cd repro
npm init -y
npm i [email protected]
echo 'a { b: 1px; }' > t.less
npx lessc t.less t.css

Current behavior:

The CLI fails before executing:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for
.../node_modules/less/bin/lessc. Loading extensionless files is not supported
inside of "type":"module" package.json contexts.

Expected behavior:

t.css is written, as in 4.5.1 and earlier.

Cause:

package.json declares "type": "module", and bin/lessc contains ESM syntax
(import path from 'path'), but the file has no extension. Node cannot resolve a
module format for an extensionless file, even inside a "type": "module" package,
so it throws before running any code.

Confirmed against the published tarball for 4.9.1:

package/bin/lessc        <- only bin entry, no extension
"type": "module"
"bin": { "lessc": "bin/lessc" }

Affected versions:

version result
4.4.2 works
4.5.1 works (last good)
4.6.0 broken (first bad)
4.9.1 broken (current latest)

Introduced by the ESM migration in #4411. The exports map added afterwards fixed
the library-side CJS regressions reported in #4423, but the bin entry appears to
have been missed — the CLI has been unusable since 4.6.0.

Suggested fix:

Rename bin/lessc to bin/lessc.js and update the bin field. Under
"type": "module" a .js file is already treated as ESM, so no other change
is needed. A bin/lessc shim could be kept if the extensionless path must
remain available.

Environment information:

  • less version: 4.6.0 through 4.9.1
  • nodejs version: v18.3.0 (the extensionless-ESM restriction is not specific
    to this version, but it is the only one I tested)
  • operating system: macOS

Activity

  1. dosubot commented on Oct 20, 2026

    @dosubot

    Hi @tomhamming! I'm Dosu and I'm helping the Personal team.

    One useful distinction: this restriction does depend on the Node version. Node 18.3.0 contains the exact error you quoted, but Node 18.20.8 explicitly handles extensionless files in a "type": "module" package as ESM. So the reproduction points to compatibility with early Node 18, rather than the CLI being unusable on every Node version. [1] [2] [3]

    The connection to #4411 fits: that migration converted bin/lessc to ESM. Less 4.9.1 still declares "node": ">=18" and points its bin entry at the extensionless file, so your Node 18.3.0 environment falls within its declared range. [4] [5]

    As a diagnostic, try the same reproduction with a newer Node runtime, ensuring the Gulp subprocess uses it too. That should avoid this particular loader error based on the later loader implementation; I haven't run the reproduction here. [2] [3]

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about less.js Share Dosu with your team

  2. tomhamming commented on Oct 20, 2026

    @tomhamming
    Author

    Yep, Dosu is correct - upgrading my node version fixes this.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions