Some quick NativeScript tips

Some quick NativeScript tips

This post is more than 2 years old.

After attending (and rather enjoying) NativeScript Developer Day last week, I'm trying to get back up to speed with NativeScript development. I've got some demos planned for integration with IBM services that I think will be pretty interesting, but I'm a bit rusty so I'm going through the docs again before I leap into making a new app. I ran into a few things today that are 100% documented, well known, etc, but still tripped me up, so I figured I'd document it purely for my own sake. All of the stuff below I figured out by first screwing it up and then getting help from Brad Martin. Thanks Brad!

Don't work in the platforms folder

Yeah, so this was especially dumb, but while debugging an issue I was having with Android, I tried modifying some code under the platforms folder even though I knew the CLI was going to blow it away. Cordova does the same thing. Stay out of platforms.

Disabling TypeScript checking (maybe!)

When I first played with NativeScript, I went the NS+JavaScript route. This time I did the TypeScript and Angular 2 route, which I strongly recommend. In general it worked fine, but I ran into some code that had issues with TypeScript, essentially it was using something that wasn't defined or imported. I knew it was going to work in runtime, but VS Code kept complaining and the CLI itself would prevent builds from happening since TypeScript was erroring out.

While this doesn't smell like the best fix, you can tell the CLI to skip over TypeScript errors by editing your tsconfig.json file and seeing noEmitOnError to false. That seems a bit weird. My only guess is that "emit" in this context means to say the error and don't actually throw it. It's true by default, so set it to false. You'll still see the errors in your console, but they won't stop your build.

Again, this feels like a bad solution, but it got me around a bug in my project.

LiveSync does not create new builds

Ok, this one was a bit subtle. The docs tell you that livesync is appropriate for view/JS type changes, but not 'deeper' stuff like plugins and the like. That makes sense. However, my thought was that when you ran livesync, it initially did a new build. What I mean is - imagine I've got livesync running and realize I need a new plugin. I kill livesync, add the plugin, and then run livesync again. In my mind, the first run in that session would do a new build. It does not. So for me, I got used to doing tns build android when I did, well, 'deep' stuff.

Messing with permissions? Uninstall first

This would apply to Cordova as well. If you are doing anything with permissions, you want to ensure you uninstall the app from the device/simulator after you've made that change. That was a big blocker for me until I figured it out.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Nathanael A posted on 9/28/2016 at 7:14 PM

One minor note -- you do not need to uninstall the app on permission changes; you do need to do the rebuild of the app like you mentioned in the prior paragraph (i.e. tns run android). LiveSync/LiveEdit only changes the css, html, xml, and js files in the app/ folder. Anything that changes the app/App_Resources or the node_modules (i.e. adding/removing a plugin) requires a full rebuild. So anything that isn't a css/html/xml/js file in your app/ folder, do a full rebuild.

Comment 2 (In reply to #1) by Raymond Camden posted on 9/28/2016 at 7:37 PM

For a while there I was trying a bunch of stuff at once, so it's possible I did that *along with* a proper build.

Comment 3 by Merott Movahedi posted on 10/5/2016 at 1:55 PM

'noEmitOnError' means don't output JavaScript code if there are errors. Setting it to 'false' tells the TS compiler to still emit JavaScript code, even if there are errors.

Comment 4 (In reply to #3) by Raymond Camden posted on 10/5/2016 at 2:02 PM

I hate the double negative there - my brain just can't handle it. :)

Comment 5 (In reply to #4) by Merott Movahedi posted on 10/5/2016 at 2:05 PM

Yeah, naming booleans with negative terms should be banned... :)

Comment 6 by Randy Johnson posted on 11/9/2016 at 1:19 PM

"LiveSync does not create new builds" Yes, I learned this the hard way. I was following a tutorial... It was working for everyone else that I asked for help. Very discouraging until I figured this out and then I felt like a rock star.