DEV Community

Arham Rumi
Arham Rumi

Posted on

Resolving "File cannot be loaded because running scripts is disabled on this system" Error in Nodemon

nodemon : File C:\Users\MyUser\AppData\Roaming\npm\nodemon.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
+ nodemon app
+ ~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
Enter fullscreen mode Exit fullscreen mode

Developers using Nodemon to enhance their Node.js development experience may encounter a common hurdle when attempting to execute the tool within a PowerShell environment. The stumbling block manifests as the error message, "File cannot be loaded because running scripts is disabled on this system," creating a roadblock in an otherwise smooth development process.

This error is a consequence of PowerShell's robust security features, specifically designed to safeguard systems from potentially harmful script execution. While these protections are vital for maintaining a secure computing environment, they can occasionally impede the seamless execution of legitimate development tools like Nodemon. There are different levels of execution policy as below:

  1. Restricted: No scripts can be run. Default for the highest level of security.
  2. AllSigned: Only scripts that are digitally signed by a trusted publisher can be run.
  3. RemoteSigned: Allows local scripts but requires downloaded scripts to be signed by a trusted publisher.
  4. Unrestricted: Allows the execution of all scripts with warnings in some cases, regardless of source.
  5. Bypass: Allows us to run scripts from anywhere without warning regardless of the source.

So, in order to resolve this issue, you have to change the execution policy. For that follow the given steps.

  • Open PowerShell as Administrator - In Start Menu, search for PowerShell. Right-click on the PowerShell icon and choose "Run as Administrator." This ensures that you have the necessary permissions to change the execution policy.

  • Get Execution Policy - Run the following command to get the current execution policy.

Get-ExecutionPolicy
Enter fullscreen mode Exit fullscreen mode
  • Change the Execution Policy - Run the following command to set the execution policy to RemoteSigned. This allows locally created scripts to run but requires scripts from the internet to be signed by a trusted publisher
Set-ExecutionPolicy RemoteSigned
Enter fullscreen mode Exit fullscreen mode

If you are prompted like below then simply type A to accept all the changes or you can choose to accept them individually by typing Y.

Changing Execution Policy

That's all. Now Run your script with nodemon again and enjoy.

Note: You may need to restart your system in some cases.

Top comments (0)