安装SASS后无法使用--watch命令,执行node-sass报错求助
I’ve run into similar issues with recent node-sass versions—let’s break down the two errors you’re seeing and fix them step by step:
1. "ENOENT: no such file or directory, lstat 'style.scss'"
This error is straightforward: node-sass can’t find your style.scss file in the directory where you’re running the command.
- First, confirm the file exists: run
ls(Mac/Linux) ordir(Windows) in your terminal to list files in the current folder. Ifstyle.scssisn’t there, either:- Move to the correct directory with
cd path/to/your/scss/folder, or - Use the full relative path to the file in your command, e.g.,
node-sass src/style.scss --watch --output dist
- Move to the correct directory with
2. "An output directory must be specified when compiling a directory"
Even if your file exists, recent node-sass builds require explicit output instructions when using the --watch flag. You have two simple fixes here:
Option A: Specify an output directory
Use the --output flag to tell node-sass where to put the compiled CSS. For example, to output to the same folder as your SCSS file:
node-sass style.scss --watch --output ./
Or to a dedicated css folder:
node-sass style.scss --watch --output css/
Option B: Directly specify the output file name
If you want to compile to a specific file (instead of a directory), just add the output file path at the end of the command:
node-sass style.scss style.css --watch
This will compile style.scss to style.css and watch for changes in the SCSS file.
Give either of these a try—they should resolve both errors. I suspect the recent node-sass update tightened up the requirements for watch mode, which is why this started happening suddenly.
内容的提问来源于stack exchange,提问作者newrobot

