Nativescript-cli: Livesync error with webstorm temporary files (3.0.0-rc.1)

Created on 19 Apr 2017  路  12Comments  路  Source: NativeScript/nativescript-cli

Did you verify this is a real problem by searching Stack Overflow and the other open issues in this repo?

I have searched, but the results seem to refer to the old occurrence of this bug (this problem or something similar was also present in 2.5.0, but went away when I switched to 2.5.2).

Tell us about the problem

The temporary editor files in Jetbrains based IDEs seem to confuse the livesync, so when I save a file while using tns run android --emulator I get errors like:

Unable to sync files. Error is: Multiple errors were thrown:
ENOENT: no such file or directory, stat '/scratch/platforms/android/src/main/assets/app/app.module.ts___jb_tmp___'

I believe the process they use for saving is something like:

  • Save to temporary file
  • Delete original
  • Rename temporary over original

Which platform(s) does your issue occur on?

Android (probably both)

Please provide the following version numbers that your issue occurs with:

  • CLI: 3.0.0-rc.1
  • Cross-platform modules: 3.0.0-rc.2
  • Runtime(s):
"tns-android": {
      "version": "3.0.0-rc.1"
    }

Please tell us how to recreate the issue in as much detail as possible.

  • Create a new angular project using tns create
  • Start the livesync tns run android --emulator
  • modify and save app/app.module.ts (or any other file really) file using webstorm (I'm currently using Webstorm 2017.1.1 on Ubuntu Linux 16.04)
bug livesync

Most helpful comment

@jbsouvestre @echap @straussCS @fvonberg @CanKattwinkel @daveware-nv
We have a quick fix for this issue. The library we use for watching the directory to know when new files are created supports mechanism to handle cases like this where there are instantly created and then deleted files.

Can you give it a try and give feedback:

  1. Locate where your local nativescript installation is:
which tns     # Result is like /usr/local/bin/tns
ls -la /usr/local/bin/tns  # Result is like /usr/local/bin/tns -> ../lib/node_modules/nativescript/bin/tns
  1. Go to your local nativescript installation folder in the livesync folder, in my case:
cd /usr/local/lib/node_modules/nativescript/lib/services/livesync
  1. Edit the livesync-service.js file with your editor at line 109
let watcher = choki.watch(pattern, { ignoreInitial: true, cwd: syncWorkingDirectory }).on("all", (event, filePath) => {

and add

awaitWriteFinish: { stabilityThreshold: 500, pollInterval: 100 }

to the options of the watch like this:

let watcher = choki.watch(pattern, { ignoreInitial: true, cwd: syncWorkingDirectory, awaitWriteFinish: { stabilityThreshold: 500, pollInterval: 100 } }).on("all", (event, filePath) => {
  1. You can then test and see if this fixes the issue. In case you experience problems you can either revert your change or re-install the nativescript.

We're waiting for your feedback

All 12 comments

Really annoying! My workflow has almost come to standstill. Affects me with Ubuntu and IntelliJ. Please fix!

I got the same problem :-( It worked in older IntelliJ/NativeScript Versions for me.

Same for me here, LifeSync not usable with Intellij IDEA

Same here, with the 3.0.0 cli ! (Ubuntu/webstorm)

I'm having the same issue but you can workaround that by disabling "safe write" in Intellij:

tooltip_710

(Tested in Webstorm)

@jbsouvestre @echap @straussCS @fvonberg @CanKattwinkel @daveware-nv
Can you reproduce the issue on macOS or Windows?

Since I have no WebStorm I simulate it with script:

sed s/Stegen/Unknown/g item.service.ts > item.service.ts____tmp___ 
rm -rf item.service.ts
mv item.service.ts____tmp___ item.service.ts

and can not reproduce on macOS Sierra.

@dtopuzov sorry only Ubuntu available. You could try with free version of IntelliJ/Webstorm

@dtopuzov Based on your script I've just added more pressure like this:

for i in {1..100}; do
    sed s/Stegen/Unknown/g item.service.ts > item.service.ts____tmp___;
    rm -rf item.service.ts;
    mv item.service.ts____tmp___ item.service.ts;
done

and I can reproduce it this way. Will try to fix it now.

@jbsouvestre @echap @straussCS @fvonberg @CanKattwinkel @daveware-nv
We have a quick fix for this issue. The library we use for watching the directory to know when new files are created supports mechanism to handle cases like this where there are instantly created and then deleted files.

Can you give it a try and give feedback:

  1. Locate where your local nativescript installation is:
which tns     # Result is like /usr/local/bin/tns
ls -la /usr/local/bin/tns  # Result is like /usr/local/bin/tns -> ../lib/node_modules/nativescript/bin/tns
  1. Go to your local nativescript installation folder in the livesync folder, in my case:
cd /usr/local/lib/node_modules/nativescript/lib/services/livesync
  1. Edit the livesync-service.js file with your editor at line 109
let watcher = choki.watch(pattern, { ignoreInitial: true, cwd: syncWorkingDirectory }).on("all", (event, filePath) => {

and add

awaitWriteFinish: { stabilityThreshold: 500, pollInterval: 100 }

to the options of the watch like this:

let watcher = choki.watch(pattern, { ignoreInitial: true, cwd: syncWorkingDirectory, awaitWriteFinish: { stabilityThreshold: 500, pollInterval: 100 } }).on("all", (event, filePath) => {
  1. You can then test and see if this fixes the issue. In case you experience problems you can either revert your change or re-install the nativescript.

We're waiting for your feedback

Hey @yyosifov ,

Thanks for the quick answer.

I just confirmed that your fix works ! Thanks !

Hello, @yyosifov your fix works for me as well. Thanks.

@jbsouvestre @echap @straussCS @fvonberg @CanKattwinkel @daveware-nv

Fix is already available in master branch of the CLI, you can try it with:

npm un -g nativescript
npm cache clean
npm i -g nativescript@next
Was this page helpful?
0 / 5 - 0 ratings