Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
Describe the bug
Whenever I try to run any CLI command (even tns --version) in PowerShell, I receive an error:
tns.ps1 : File C:\Users\vladimirov\AppData\Roaming\npm\tns.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\tns.ps1
+ ~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
To Reproduce
npm i -g npmnpm i -g nativescripttns --version in PowerShell on WindowsExpected behavior
The commands should work.
Additional context
Everything works fine in CMD.
In newer npm versions, when a global package is installed, npm creates three different executables for it:
.cmd executable - used by default on Windows in Command-Prompts.ps1 executable - used by default in PowerShell.With previous versions the .ps1 executable was not created by npm and when trying to run tns in PowerShell, the .cmd executable was used.
Due to this change, the tns (and any other newly installed global packages) cannot be executed by default on Windows as the default Execution Policy on Windows is set to Restricted, i.e. it does not allow execution of any scripts.
To change this, you can set different execution policy on your machine as described here:
For example, in case you want to change the execution policy only for the current PowerShell process (i.e. do not persist the value between sessions), you can execute:
```PowerShell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
````
NOTE: This will prompt you to confirm the change - select "Yes"
After that you should be able to execute tns commands.
Hello,
I have exactly the same problem.
Unfortunately, the given link no longer works.
Is there a solution for the problem or a good workaround?
Thanks for your help
I can't vouch for any downstream impact this may have, but I just went into my "C:\Users{USER}\AppData\Roamingnpm\" folder and removed the tns.ps1 file and was able to run tns commands again. Still only a temporary solution as an upgrade to the NS cli results in the file being recreated.
While using vscode trying to run react native, I kept getting the same error non of the command lines worked. Deleting the folder from the NPM files was the only solution that worked for me.
Most helpful comment
In newer
npmversions, when a global package is installed,npmcreates three different executables for it:.cmdexecutable - used by default on Windows in Command-Prompts.ps1executable - used by default in PowerShell.With previous versions the
.ps1executable was not created bynpmand when trying to runtnsin PowerShell, the.cmdexecutable was used.Due to this change, the
tns(and any other newly installed global packages) cannot be executed by default on Windows as the default Execution Policy on Windows is set to Restricted, i.e. it does not allow execution of any scripts.To change this, you can set different execution policy on your machine as described here:
For example, in case you want to change the execution policy only for the current PowerShell process (i.e. do not persist the value between sessions), you can execute:
```PowerShell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
````
NOTE: This will prompt you to confirm the change - select "Yes"
After that you should be able to execute
tnscommands.