Node版Sass编译注释报错:Expected expression问题咨询
Hey there, I've run into this exact issue before when migrating from Ruby Sass to Dart Sass (the modern Node-based Sass implementation), so let's walk through what's going on and how to fix it.
Why This Error Happens
Ruby Sass was pretty lenient with loose syntax, including how inline comments were placed after property values. But Dart Sass (the version you're now using via Node) enforces stricter adherence to CSS/Sass syntax rules.
In your case, the comment is directly appended to the property value without a space:
position: fixed/* Here's what sticks it*/
Dart Sass interprets fixed/* Here's what sticks it*/ as a single, invalid property value instead of recognizing the comment as separate from the fixed keyword. That's why you get the "Expected expression" error.
Quick Fixes & Solutions
Add a space before the inline comment: The simplest fix is to insert a space between the property value and the comment. Your line should look like this:
position: fixed /* Here's what sticks it*/This tells Dart Sass to treat
fixedas the valid property value and the following/* ... */as a separate comment.Batch replace with regex (for multiple files): If you have dozens or hundreds of files with this issue, use a regex find-and-replace in your code editor or build tool to fix all instances at once. Here's a regex pattern you can use:
- Find:
([a-zA-Z0-9-]+):([^\s/]+)/\* - Replace:
$1: $2 /*
This will automatically add a space between the property value and any inline comment that's missing it.
- Find:
Audit other loose Ruby Sass syntax: While you're at it, keep an eye out for other syntax that Ruby Sass allowed but Dart Sass rejects—like missing spaces around colons, or certain nested selector shortcuts. Running a full Sass compile with the
--strictflag can help catch these early.
内容的提问来源于stack exchange,提问作者Bauke

