sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.87k stars 350 forks source link

Switching git branches while in watch mode causes 'can't find stylesheet to import' #2271

Closed angelikatyborska closed 1 month ago

angelikatyborska commented 1 month ago

Switching branches while sass --watch is running causes a Error: Can't find stylesheet to import. error when the switch causes one of the dependent files to be removed even if at the same time other files are changed so that the removed file is no longer needed after the branch switch.

Reproduction

Here's a reproduction repository: https://github.com/angelikatyborska/sass-watch-bug

To reproduce the bug, follow those steps:

  1. Checkout the repository, main branch
  2. Run npm install
  3. Confirm that sass build works on main by running npm run build:scss
  4. Checkout the apple branch. It contains an extra file that's also @use'd from the input scss file in.scss.
  5. Confirm that sass build works on apple by running npm run build:scss
  6. Start watch mode by running npm run build:scss:watch
  7. Checkout main branch while sass is running in watch mode
  8. Observe unexpected build errors: Error: Can't find stylesheet to import.

Video demo

https://github.com/sass/dart-sass/assets/7852553/b869ef7f-0332-4989-81f1-45af58b663ce

Dependency versions

Please let me know if the reproduction steps and repo are clear and what other details you need to debug this 🙂

angelikatyborska commented 1 month ago

I just noticed that the error does not happen when I close my IDE (Webstorm) and run sass from iterm2 instead of my IDE's built in terminal. Is it possible that my IDE is interfering with the watch mode?

My teammates who use a different IDE (VSCode) experience the same issue.

nex3 commented 1 month ago

Unfortunately, we're fairly constrained here by the information provided by the operating system's filesystem watching API and the way that information is interpreted by the watcher library we use (in this case chokidar). Having implemented a watcher library in the past, I can say that the MacOS watcher API is particularly finicky, often reporting information that's incomplete, contradictory, or out-of-order.

The best workaround I can offer is passing --poll, which will skip the OS-level filesystem watcher entirely in favor of manually checking for new files every second. It won't be as efficient, but it'll be more likely to be robust in the face of whatever filesystem shenanigans Git is pulling.

fonziemedia commented 6 days ago

Having a similar issue in a WSL/ubuntu/docker dev environment. When switching branches it compiles the CSS for the branch I'm switching from not the branch I'm switching into. A bit annoying but for now I just have to stop the watcher before switching branches or revert the changes..

Seem like chokidar has a major update coming soon, maybe it will fix this?