Tuesday, July 26, 2016

NativeScript + Angular 2: How to fix TNSLabel error

When using NativeScript + Angular 2, some strange errors may occur as Angular 2 is in RC and has many issues yet. Therefore some strange errors occur.

I've encountered such error while running my app in iOS emulator:

CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:419:27: Unhandled Promise rejection: Can't find variable: TNSLabel ; Zone: angular ; Task: Promise.then ; Value: ReferenceError: Can't find variable: TNSLabel

The fix is rather easy - just remove and add the iOS platform.

tns platform remove ios
tns platform add ios

 Run your app again and you're all set!

How to: Setup genymotion/genyshell commands in zsh

After you install Genymotion on MacOS, it's installed in the Applications folder. Unfortunately, the PATH variable is not set automatically, therefore running:
in the Terminal will result in an error.

In order to fix this, so that every time you open the Terminal or restart your PC, you need to setup your profile to export and add the correct paths to the $PATH variable. Here are the steps for zsh users:

  1. Open the zsh profile for editing: sudo vi ~/.zshrc
  2. Add the following lines at the end of the file, so that the genymotion paths for App and Shell are both added tot he $PATH on startup. In previous/next versions, the paths to the Genymotion.app and Shell may have changed so you can verify these.

          export GENYMOTION_APP=/Applications/Genymotion.app/Contents/MacOS
          export GENYMOTION_SHELL=/Applications/Genymotion\ Shell.app/Contents/MacOS/

          export PATH=$PATH:$GENYMOTION_APP

      3. You can now test your setup by running source ~/.zshrc which will execute in the current terminal your updated profile script
      4. You can see the PATH contents with echo $PATH or try running genymotion and genyshell from terminal.

Happy scripting!