The term tns is not recognized as the name error

The term ‘tns’ is not recognized as the name error

If you are using NativeScript for the first time, and you want to launch a mobile application, you might get an error related to tns. Basically, if you are using Windows OS, you will get an error code that looks like this:

tns : The term ‘tns’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

If you came to this problem when you were trying to develop your first native mobile, you might be wondering, what is tns? Basically, it is a command-line interface tool of the NativeScript framework. For someone who is just starting with the NativeScript development might be confusing what this error should mean. However, this might happen even for someone who is experienced, in case he is starting to work in a clean environment without any installations of Node packages. Let’s see how we can fix it.

An obvious solution is to check if the NativeScript is installed. You can do this by simply going into YourUser\Roaming\npm\node_modules directory. There you should see a folder called typescript. If there is no TypeScript installed, executing this command in the terminal will get it for you:

npm install -g nativescript

After the installation, it should work. You can try running the tns command. If that didn’t work, well, it seems like the problem is not with the NativeScript installation. It’s possible that the npm directory is not set into the Windows path. Here are some steps how you can make, to get the tns working:

  • Open the Control Panel and go to the System and Security, then System and click on the Advanced system settings that is located on the left
  • Click on the Environment Variables
  • Select the variable named Path and click Edit button
  • Now check if there is a line for npm path. If it’s not there, add a line that looks like this C:\Users\Your-User\AppData\Roaming\npm:
Solve tns is not recognized error by adding npm to path

After this, try executing tns in the terminal. Now it should work.

Leave a Comment