Nativescript-cli: tns_modules randomly appears in app folder and breaks build

Created on 29 Jul 2017  路  12Comments  路  Source: NativeScript/nativescript-cli

Hi Guys,

A folder called tns_modules is randomly added to the app folder. The contents seem to be a subset of node_modules.

Once the folder appears, you cannot use tns run / build etc. Deleting the folder fixes these issues.

Why does tns_modules get created?

I am using TNS 3.1.3 on a Mac, this happened in 3.1.0 as well.

Regards,
Tarek

bug

Most helpful comment

Hey all,
I've finally reproduced the issue and found what's causing it. It's pretty tricky, but I'll try to explain it with full details.
The issue can be reproduced only when using iOS Simulator. For communication with simulators, CLI uses a library called ios-sim-portable. We have extracted the code for communication with the simulator in this library for easier maintenance. The ios-sim-portable library spawns xcrun simctl commands in order to get required information. In order to use sync code, we are using spawnSync method of Node.js. However, this method has some "specialties". The problem here is that sending any kill signal to CLI (like Ctrl + C, which sends SIGINT) while spawnSync is working may not be propagated to CLI's main process. This may happen in case the spawned executable (xcrun simctl in this case) handles the signal on its own. And of course, that's our case. So using Ctrl + C while ios-sim-portable is currently working with xcrun simctl will just make the spawned process to die, but CLI will continue its work.
And here comes the second part of the issue - during LiveSync (tns run ios) CLI is trying to get the path where to send the synced files. In order to find the place, CLI calls ios-sim-portable, which executes xcrun simctl get_app_container <device id> <app id>. In case SIGINT is send during execution of this command, ios-sim-portable will return empty string and CLI will add app/tns_modules to it. So the path, where CLI will try to copy files for LiveSync becomes ./app/tns_modules. CLI's process continues its work and starts copying files to ./app/tns_modules.

The xcrun simctl commands are executed really fast, so its tricky to reproduce the issue. You have to try tns run ios and press Ctrl + C exactly when the xcrun simctl get_app_container is spawned. However, I've managed to reproduce it by hanging the iOS Simulator itself. I've started tns run ios in two separate terminals for the same project (note: the second command is started some time after the first one). At some point I've stopped both processes with Ctrl + C and tried calling the xcrun simctl get_app_container <device id> <app id> manually and it just hanged. So after that, executing tns run ios hangs at some point, waiting for the result of the mentioned command. At this point, pressing Ctrl + C should kill CLI, however it just continues and creates the tns_modules dir in app of the project.

In order to fix the issue, we'll update ios-sim-portable to respect the signal property of the result of the spawned process and ensure it is correctly passed to CLI as well. This way, pressing Ctrl + C will be sent to both xcrun commands and to CLI and the tns_modules directory will not be created on incorrect place, as CLI's process will die as well.

All 12 comments

Hi @thaoula

Can you specify version of node and npm on your machines?
If you can also isolate workflow that reproduce the issue it will be great.

Hi @dtopuzov,

I am using npm 5.3.0 and node 8.

I am still trying to identify the workflow that causes tns_modules to be created. Unfortunately, i have been unable to work out any repeatable steps.

However, it happened several times yesterday.

Regards,
Tarek

Hi @thaoula

Thanks for the info.
Two more questions:

  • Do you use npm link in your development workflow?
  • Do you use some dev plugins like nativescript-dev-sass or nativescript-dev-less (something that modify files in the project while you develop)?

Hi @dtopuzov,

Thanks for getting back to me -
I use nativescript-dev-less and I also use npm link for our model project.

Is there anyway to debounce watches or ignore files?

Regards,
Tarek

Hi @thaoula

We do not have such feature available at the moment, but it is in the backlog: https://github.com/NativeScript/nativescript-cli/issues/887

The issue seems to happen only if you have npm5 and use npm link.
We will try to fix it for next release(s) and until then you can try to workaround it via downgrade to npm4.

@thaoula If you could provide us with the steps to reproduce the issue, that will contribute to how fast it will be fixed. Thank you!

Hi @dtopuzov
Am having the same problem and am not using npm link in the development workflow.
Also not using dev plugins like nativescript-dev-sass or nativescript-dev-less.

Once I delete the tns_modules folder everything works.
Thanks

I've run into this issue multiple times, and I'm using NPM 6.10.1. I don't use npm link and do not use nativescript-dev-sass or nativescript-dev-less.

NPM 3.10.10, with nativescript-dev-sass, and the same issue exists.

I just had app/tns_modules created when I ran tns install. I had never used that before and instead have used npm install, which correctly places the modules in ./node_modules.

I was having the same problem (tns_modules appearing and the build not working) with {N} 3.2.1, only when I ran on the iOS 11 Simulators. The following commands fixed my issue:

tns platform remove ios
tns platform add ios

Hey all,
I've finally reproduced the issue and found what's causing it. It's pretty tricky, but I'll try to explain it with full details.
The issue can be reproduced only when using iOS Simulator. For communication with simulators, CLI uses a library called ios-sim-portable. We have extracted the code for communication with the simulator in this library for easier maintenance. The ios-sim-portable library spawns xcrun simctl commands in order to get required information. In order to use sync code, we are using spawnSync method of Node.js. However, this method has some "specialties". The problem here is that sending any kill signal to CLI (like Ctrl + C, which sends SIGINT) while spawnSync is working may not be propagated to CLI's main process. This may happen in case the spawned executable (xcrun simctl in this case) handles the signal on its own. And of course, that's our case. So using Ctrl + C while ios-sim-portable is currently working with xcrun simctl will just make the spawned process to die, but CLI will continue its work.
And here comes the second part of the issue - during LiveSync (tns run ios) CLI is trying to get the path where to send the synced files. In order to find the place, CLI calls ios-sim-portable, which executes xcrun simctl get_app_container <device id> <app id>. In case SIGINT is send during execution of this command, ios-sim-portable will return empty string and CLI will add app/tns_modules to it. So the path, where CLI will try to copy files for LiveSync becomes ./app/tns_modules. CLI's process continues its work and starts copying files to ./app/tns_modules.

The xcrun simctl commands are executed really fast, so its tricky to reproduce the issue. You have to try tns run ios and press Ctrl + C exactly when the xcrun simctl get_app_container is spawned. However, I've managed to reproduce it by hanging the iOS Simulator itself. I've started tns run ios in two separate terminals for the same project (note: the second command is started some time after the first one). At some point I've stopped both processes with Ctrl + C and tried calling the xcrun simctl get_app_container <device id> <app id> manually and it just hanged. So after that, executing tns run ios hangs at some point, waiting for the result of the mentioned command. At this point, pressing Ctrl + C should kill CLI, however it just continues and creates the tns_modules dir in app of the project.

In order to fix the issue, we'll update ios-sim-portable to respect the signal property of the result of the spawned process and ensure it is correctly passed to CLI as well. This way, pressing Ctrl + C will be sent to both xcrun commands and to CLI and the tns_modules directory will not be created on incorrect place, as CLI's process will die as well.

Was this page helpful?
0 / 5 - 0 ratings