Windows Powershell - "running scripts is disabled on this system" when running `nexmo`
Steps to reproduce
On Windows 10:
- Install the latest version of NodeJS from https://nodejs.org/en/
- Install the CLI with
nexmo-cli@beta -g - Run
nexmo
Expected behavior
I should see the help output from the nexmo command.
Actual behavior
nexmo : File C:\Users\chris\AppData\Roaming\npm\nexmo.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
+ nexmo
+ ~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
This normally occurs when the remote script isn't trusted. I could get it to run by changing my Execution Policy to "RemoteSigned", at which point the CLI worked again:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
It looks like at some point after npm 6.9.0, npm started generating a nexmo.ps1 file to help wrap the node SDK in the event node is installed both under Powershell and Linux. This ps1 file will not run under the default "Restricted" execution policy Windows 10 ships with.
npm 6.9.0 and prior do not generate this file, and worked fine.
Other projects with this same general issue:
- Firebase - https://github.com/firebase/firebase-tools/issues/1627
- Angular CLI - https://stackoverflow.com/questions/58880139/electron-node-js-ng-file-path-ng-ps1-cannot-be-loaded-because-running-scri
System configuration
Node version: 12.16.3
NPM version: Broken under 6.14.4 Works under 6.9.0
Operating system: Windows 10 Professional under Powershell