Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
angelikatyborska opened this issue Jun 27, 2024 · 3 comments

Comments

@angelikatyborska
Copy link

angelikatyborska commented Jun 27, 2024

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

screen-recording.mp4

Dependency versions

  • dart-sass: 1.77.6
  • operating system: macOS Sonoma 14.5
  • git: 2.39.3 (Apple Git-146)

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

@angelikatyborska
Copy link
Author

angelikatyborska commented Jun 27, 2024

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
Copy link
Contributor

nex3 commented Jul 1, 2024

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.

@nex3 nex3 closed this as completed Jul 1, 2024
@fonziemedia
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants