Search code examples
node.jswindowsangularwebstormwindows-subsystem-for-linux

WebStorm cannot save file when using ng serve


When using ng serve --open --live-reload to serve an Angular app on my development machine, and using WebStorm to change the files I get the error "cannot save file" when WebStorm tries to save.

When I edit the file in Sublime I have no issues so it looks like the files are not locked by ng serve.

Dev setup


Solution

  • It was not ng serve locking files, nor any interactions between ubuntu and windows. It was the manner in which webstorm saves files by default.

    By default webstorm will save a copy of the file with a tmp name, delete the original then rename your copy to be the same as the one just deleted. It looks like this process (which happens very fast) was interacting with ng serve in some odd manner causing the file to fail to be renamed leaving a funny tmp file behind.

    The solution is to turn off 'Use "safe write" (save changes to a temporary file first)' in the 'system settings' under 'Appearance and behaviour' in the webstorm settings.