2 minutes
How to Fix ‘bower.ps1 cannot be loaded because running scripts is disabled’ Error on Windows using PowerShell
Bower is a package manager that facilitates the installation of the correct version of packages in your project. While these days tools such as yarn
, parcel
, or webpack
are more popular, a lot of old projects still use bower
to manage the dependencies.
Backstory
On Monday, I had to build a front-end project developed 7+ years ago and it happened to be using bower. I started by running npm install -g bower
to install bower globally on my system.
Then, I ran bower install
in the root directory of the project which is supposed to automatically pull and install the project dependencies that are managed by bower. I was perplexed when the command failed with an error message: bower.ps1 cannot be loaded because running scripts is disabled on this system
.
Solution
As usual, I resorted to the web to investigate the cause of the error and I landed on the documentation for PowerShell. The topic was about Execution Policies. I learned that PowerShell has a safety feature which determines what kinds of scripts it is allowed to execute. Additionally, the policies are enforced on Windows platforms only. The current execution policy can be viewed using the command below:
Get-ExecutionPolicy
The default execution policy was Restricted
on my system.
The PowerShell documentation lists all the possible execution policies:
- AllSigned
- Bypass
- Default
- RemoteSigned
- Restricted
- Undefined
- Unrestricted
The description for the RemoteSigned
policy caught my attention and seemed to be the most appropriate one for my scenario:
“Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the internet which includes email and instant messaging programs.”
“Doesn’t require digital signatures on scripts that are written on the local computer and not downloaded from the internet.”
Fortunately, changing the PowerShell execution policy to RemoteSigned
was quite easy:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
I ran bower install
again, and it successfully restored all the required dependencies in the front-end project 🎉.
Comments
Please wait...