Repository: less/less.js (2025-08-26T23:30:02Z)

Issue:
`@media print` throwing an error after upgrading from LESS 4.4.0 to 4.4.1
**To reproduce:**

Upgrade from 4.4.0 to 4.4.1.

**Current behavior:**

```
10:26:32  [error] ✗ Build failed in 15.95s
10:26:32  [error] error during build:
10:26:32  [vite:css-post] [lightningcss minify] Unexpected token Function("print")
10:26:32  
10:26:32  12984|    flex-direction: row;
10:26:32  12985|  }
10:26:32  12986|  @media print(max-width: 992px) {
10:26:32     |        ^
10:26:32  12987|    .main-view {
10:26:32  12988|      display: flex;
10:26:32  
10:26:32      at minifyCSS
```

**Expected behavior:**

Vite build should work as usual.

**Environment information:**

<!-- Provide the `less` and `nodejs` packages versions -->

- `less` version: 4.4.1
- `nodejs` version: 22.14.0
- `operating system`: Windows 11, Linux
<!-- macos, linux or windows ? -->

<!-- feel free to add additional comments -->



Discussion:
<!-- Greeting -->
Hi @kgetz-arista! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the less.js team.

<!-- Answer -->
This error happens because LESS 4.4.1 enforces stricter CSS media query syntax. The parser now requires a space between the media type and the feature, so `@media print(max-width: 992px)` is invalid and should be written as `@media print and (max-width: 992px)`. Without the space and the `and`, LESS emits CSS like `print(max-width: 992px)`, which downstream tools (like lightningcss) interpret as a function call, causing the build to fail with an "Unexpected token Function('print')" error. 

To fix this, update your LESS to use the standard syntax: `@media print and (max-width: 992px)` or `@media (print) and (max-width: 992px)` [reference](https://github.com/less/less.js/issues/4331).


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/550780ed-05fb-4f35-893a-ea2c8ff53f41?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/550780ed-05fb-4f35-893a-ea2c8ff53f41?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/550780ed-05fb-4f35-893a-ea2c8ff53f41?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/550780ed-05fb-4f35-893a-ea2c8ff53f41?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/550780ed-05fb-4f35-893a-ea2c8ff53f41?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/550780ed-05fb-4f35-893a-ea2c8ff53f41?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/550780ed-05fb-4f35-893a-ea2c8ff53f41?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/c9543198-f3c1-4355-832e-62ee978588c8/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/less/less.js/issues/4362)
Our original code has an OR (not an AND), so this isn't quite correct. Here's our code which is being incorrectly transformed now:

```
@media print, (max-width: 992px) {
```

It appears that this is being wrongly transformed to this:

```
@media print(max-width: 992px) {
```
Glancing at the changelog for this release, maybe #4349 is the reason for the change in behavior? @puckowski 
This issue can be reproduced [using the Less-to-CSS playground](https://lesscss.org/less-preview/#eyJjb2RlIjoiI2xpYigpIHtcbiAgICAuY29sb3JzKCkge1xuICAgICAgQHByaW1hcnk6IGJsdWU7XG4gICAgICBAc2Vjb25kYXJ5OiBncmVlbjtcbiAgICB9XG4gICAgLnJ1bGVzKEBzaXplKSB7XG4gICAgICBib3JkZXI6IEBzaXplIHNvbGlkIHdoaXRlO1xuICAgIH1cbiAgfVxuICBcbiAgLmJveCB3aGVuICgjbGliLmNvbG9yc1tAcHJpbWFyeV0gPSBibHVlKSB7XG4gICAgd2lkdGg6IDEwMHB4O1xuICAgIGhlaWdodDogKCR3aWR0aCAvIDIpO1xuICB9XG4gIFxuICAuYmFyOmV4dGVuZCguYm94KSB7XG4gICAgQG1lZGlhIHByaW50LCAobWluLXdpZHRoOiA2MDBweCkge1xuICAgICAgd2lkdGg6IDIwMHB4O1xuICAgICAgI2xpYi5ydWxlcygxcHgpO1xuICAgIH1cbiAgfSIsImFjdGl2ZVZlcnNpb24iOiI0LjQuMSIsIm1hdGgiOiJwYXJlbnMtZGl2aXNpb24iLCJzdHJpY3RVbml0cyI6ZmFsc2V9) for version 4.4.1. With Less version 4.3.0, [the output is correct](https://lesscss.org/less-preview/#eyJjb2RlIjoiI2xpYigpIHtcbiAgICAuY29sb3JzKCkge1xuICAgICAgQHByaW1hcnk6IGJsdWU7XG4gICAgICBAc2Vjb25kYXJ5OiBncmVlbjtcbiAgICB9XG4gICAgLnJ1bGVzKEBzaXplKSB7XG4gICAgICBib3JkZXI6IEBzaXplIHNvbGlkIHdoaXRlO1xuICAgIH1cbiAgfVxuICBcbiAgLmJveCB3aGVuICgjbGliLmNvbG9yc1tAcHJpbWFyeV0gPSBibHVlKSB7XG4gICAgd2lkdGg6IDEwMHB4O1xuICAgIGhlaWdodDogKCR3aWR0aCAvIDIpO1xuICB9XG4gIFxuICAuYmFyOmV4dGVuZCguYm94KSB7XG4gICAgQG1lZGlhIHByaW50LCAobWluLXdpZHRoOiA2MDBweCkge1xuICAgICAgd2lkdGg6IDIwMHB4O1xuICAgICAgI2xpYi5ydWxlcygxcHgpO1xuICAgIH1cbiAgfSIsImFjdGl2ZVZlcnNpb24iOiI0LjMuMCIsIm1hdGgiOiJwYXJlbnMtZGl2aXNpb24iLCJzdHJpY3RVbml0cyI6ZmFsc2V9).
@kgetz-arista Thank you for the bug report. Surprised the tests missed the regression, but this should be resolved by https://github.com/less/less.js/pull/4363

I am short on time today but I'll add more tests to https://github.com/less/less.js/pull/4363 tomorrow and hopefully we can get it merged soon.
Thanks for the quick fix! 🚀 
Is this fix going to be released soon? The latest version on npm is still 4.4.1.



Patch:
diff --git a/packages/less/src/less/parser/parser.js b/packages/less/src/less/parser/parser.js
index 99036cbe1..76676f5fe 100644
--- a/packages/less/src/less/parser/parser.js
+++ b/packages/less/src/less/parser/parser.js
@@ -1949,11 +1949,17 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
                     if (e) {
                         features.push(e);
                         if (!parserInput.$char(',')) { break; }
+                        else if (!features[features.length - 1].noSpacing) {
+                            features[features.length - 1].noSpacing = false;
+                        }
                     } else {
                         e = entities.variable() || entities.mixinLookup();
                         if (e) {
                             features.push(e);
                             if (!parserInput.$char(',')) { break; }
+                            else if (!features[features.length - 1].noSpacing) {
+                                features[features.length - 1].noSpacing = false;
+                            }
                         }
                     }
                 } while (e);
diff --git a/packages/less/src/less/tree/nested-at-rule.js b/packages/less/src/less/tree/nested-at-rule.js
index 0060755ab..fc383f344 100644
--- a/packages/less/src/less/tree/nested-at-rule.js
+++ b/packages/less/src/less/tree/nested-at-rule.js
@@ -31,7 +31,7 @@ const NestableAtRulePrototype = {
         for (let index = 0; index < exprValues.length; ++index) {
             expr = exprValues[index];
 
-            if (expr.type === 'Keyword' && index + 1 < exprValues.length) {
+            if (expr.type === 'Keyword' && index + 1 < exprValues.length && (expr.noSpacing || expr.noSpacing == null)) {
                 paren =  exprValues[index + 1];
                 
                 if (paren.type ===  'Paren' && paren.noSpacing) {


Test patch:
diff --git a/packages/test-data/css/_main/media.css b/packages/test-data/css/_main/media.css
index 62cffe6a6..d471401e8 100644
--- a/packages/test-data/css/_main/media.css
+++ b/packages/test-data/css/_main/media.css
@@ -264,3 +264,8 @@
     padding: 0;
   }
 }
+@media print, (max-width: 992px) {
+  div {
+    color: red;
+  }
+}
diff --git a/packages/test-data/less/_main/media.less b/packages/test-data/less/_main/media.less
index c66802747..232e6379f 100644
--- a/packages/test-data/less/_main/media.less
+++ b/packages/test-data/less/_main/media.less
@@ -291,3 +291,9 @@
     }
   }
 }
+
+@media print, (max-width: 992px) {
+    div {
+        color: red;
+    }
+}