Menu

#2386 Fix 'unreadable file error' in watch mode after a save in vscode

open
nobody
None
2018-06-25
2018-05-18
Anonymous
No

Originally created by: marcosbozzani

This fix detects 'File to read not found or unreadable' and 'File to import not found or unreadable' errors that occasionally happens after a file save in Visual Studio Code when node-sass is running on watch mode.

If those errors are detected, a retry mechanism is applied. It verifies that the file actually exists and limits the maximum number of retries to 1000. In my local tests, it usually takes less than 5 retries. The limit is there as a safety measure to prevent infinite recursion and the value is high enough for those cases where the machine is really slow or it has to access a storage with high latency, like a remote one.

Those errors happen with 'node-sass (watch mode)', 'chokidar + node-sass' and 'node-sass-chokidar (watch mode)' too.

It is also possible to change the retry mechanism for one with exponential backoff. For example:

Change this code:

if (isFileUnreadable(error) && retries < 1000) {
      retries++;
      sass.render(renderOptions, renderCallback);
}

For this one:

if (isFileUnreadable(error) && retries < 4) {
      retries++;
      setTimeout(() => sass.render(renderOptions, renderCallback), Math.pow(retries, 5));
}

Related issues:
https://github.com/sass/node-sass/issues/1894
https://github.com/sass/node-sass/issues/2022
https://github.com/Microsoft/vscode/issues/20491
https://github.com/facebook/create-react-app/issues/2531
https://github.com/michaelwayman/node-sass-chokidar/issues/14
https://github.com/michaelwayman/node-sass-chokidar/issues/22
https://stackoverflow.com/questions/50395998/vscode-wont-work-with-filewatchers

Discussion

  • Anonymous

    Anonymous - 2018-05-18

    Originally posted by: marcosbozzani

    Sorry if I wasn't clear enough in the PR. I know it's not node-sass fault. Yet this cause a very annoying issue for node-sass users. This could serve as a temporary workaround that could be removed once the real issue was solved. It doesn't affect those editors that do that right thing and mitigate the problem until the other editors can be fixed.

    Chokidar fails as well (chokidar + node-sass and node-sass-chokidar), as you can see in the related issues. 😕

    I'm just sharing the solution that worked for me, so anyone can use it. 😉

    If this is really not the right place for this patch, I'm sorry for the trouble. 😅

     
  • Anonymous

    Anonymous - 2018-06-02

    Originally posted by: maartenraes

    @marcosbozzani worked for me by replacing the file localy, many thanks! 👍

     
  • Anonymous

    Anonymous - 2018-06-25

    Originally posted by: derek126

    This would be great to have. This issue is very annoying.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.