How to fix error- nodemon.ps1 cannot be loaded because running scripts is disabled on this system, (without security risk)?
Asked Answered
S

19

151

Error on terminal: nodemon.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

I have a solution to fix the issue by this way:

1. Open Windows PowerShell with Run as Administrator
2. Run this command: Set-ExecutionPolicy Unrestricted

That solves the issue, but this way the system shows Security Risk Warning.
My question: Is there any other way to solve this without security risk? Target is to use nodemon.

Stelliform answered 15/8, 2020 at 7:20 Comment(2)
can you provide more details ?Itagaki
Please read the help files on Executpm Policies. About_Execution_Policies - PowerShell | Microsoft Docs There is little reason in normal operation to use an EP of unrestricted. RemoteSigned is the default. You host should be set as the most restricted for yourself or your org. You can run a PowerShell session/script using a different EP. EP is not a security boundary.Squeteague
A
362

I'd recommend using RemoteSigned as opposed to Unrestricted, and limiting the policy to the CurrentUser if possible.

Run Powershell as Admin, and then:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

RemoteSigned: "The default execution policy for Windows server computers."



Other than that, I wouldn't worry about it too much, as it's not intended to be a security mechanism. See this quote from the docs:

"The execution policy isn't a security system that restricts user actions. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally."

Aguilera answered 15/8, 2020 at 9:56 Comment(4)
Is there anyway to set this policy by command promt?Puritan
@TommyHoang, run CMD as admin, then: cmd.exe /c powershell -command Set-ExecutionPolicy RemoteSignedAguilera
Work like a champ, ty mate.Colorimeter
it is working fineDiploma
I
60

For those who are not aware of how to solve this error using Windows PowerShell

  1. Open PowerShell (Run As Administrator)
  2. Check the current execution policy using this command
    Get-ExecutionPolicy
    # You should get 'Restricted'
  1. Run this command to make it 'Unrestricted'
    Set-ExecutionPolicy Unrestricted
  1. Check again whether execution policy changed by running this command
    Get-ExecutionPolicy
    # You should get 'Unrestricted'
  1. Now try to run nodemon on your project
    nodemon 'filename.js'

Hope this would be helpful

Immorality answered 29/12, 2020 at 6:32 Comment(3)
Setting the execution policy to Unrestricted is unnecessary and non-optimal in this case, and is kind of a footgun.Aguilera
This saved my time. I appreciate very much.Kellyekellyn
This actually worked like a charm for me. Thanks!Cockayne
M
52

Step 1 : Go to this location --> File C:\Users\Dell\AppData\Roaming\npm
Step 2 : Delete the nodemon.ps1 file and run the command.

Mendymene answered 22/3, 2021 at 9:4 Comment(3)
this is the easiest , and it worked , thanksBackwater
amazing, can you explain ?Spermaceti
It works... but i dont know why hahaSailer
F
21

There is no security risk whatsoever associated with allowing remoted signed scripts to run on your local machine. It basically means you can execute local unsigned scripts i.e scripts written by you while scripts from a remote source (nodemon in this case) must be signed by a trusted authority.

P.S: If you're on windows, you can just go to settings >> update and security >> for developers >> check the box beside change execution policy to allow local powershell scripts to run without signing

Fleshly answered 15/8, 2020 at 15:41 Comment(1)
Thank you, This worked for me. - - - BUT NB: the check box was already checked, and so I toggled it and that fixed the issue. For me the account being used was my sons child account on the crappy Family Product with Admin access, and so this issue I believe was caused by Family Product.Ardeth
S
17

This command might help

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Syringa answered 20/10, 2020 at 13:27 Comment(1)
That worked for me and the serve is working with localhost:5000Neap
G
13

I've a better solution, just go to the folder where nodemon.ps1 places (path is in error) and delete nodemon.ps1 file.

now go to the terminal and run nodemon -v, if you get a version then the problem solved.

Grayce answered 27/1, 2021 at 6:55 Comment(0)
Y
8

While using npm I recommend to bridge the nodemon command in the scripts section and leave the security settings as they are.

package.json:

{
    "scripts": {
        "hmr": "nodemon index.js",
        "nodemon": "npm run hmr",
        "start": "node index.js"
    },
    "dependencies": {}
}

Just execute npm run nodemon which will run the hmr line behind the scenes.

Yoshieyoshiko answered 22/12, 2020 at 9:36 Comment(0)
C
8

You can do this by without changing the policy. C:\Users\HP MICROTECH\AppData\Roaming\npm\nodemon.ps1 (path is given at error screen)

just go to this path and delete nodemon.ps1

and there your nodemon runs.

Checkerwork answered 26/7, 2021 at 6:46 Comment(2)
Noticed there are two scripts there. One is a cmd script while the other is a powershell. With the powershell script deleted, it will default to the cmd script but you will notice a very minimal delay which is not noticeable persayRefugia
Perfect and easy. Once removed I got nodemon to start normally with "nodemon start". Thank you!Woodall
D
8

The best way to get rid of this error is
Run the below command in your windows power shell as admin

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Basically it will ask you to change the execution policy then type Y .

                  **OR**

You can do is without changing your execution Policy

  1. Install nodemon using this command : npm i nodemon -g
  2. then type nodemon -v you will see a path in first line of error go to that path then delete that nodemon.ps1 file or filename with.ps1xml extension.

Make sure that you are installing nodemon globally For more details microsoft execution policies docs

Donetta answered 25/9, 2021 at 17:39 Comment(0)
C
4

This cmd works properly.

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Custombuilt answered 17/5, 2021 at 15:15 Comment(1)
This answer doesn't add anything newAguilera
K
3

Faced Similar issue while running some node command. AppData\Roaming\npm\serverless.ps1 cannot be loaded because running scripts is disabled on this system.

PS C:\Users\adas67> Get-ExecutionPolicy
Restricted

PS C:\Users\adaaa> Get-ExecutionPolicy -List

Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined

Solved by this.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Keramic answered 1/11, 2021 at 6:41 Comment(0)
C
2

Go to the folder : - C:\Users\admin\AppData\Roaming\npm

Delete the powershell file of nodemon or nodemon.ps1 . You will be good to go.

Chromaticness answered 25/7, 2021 at 14:38 Comment(0)
G
1

Run these commands:

  1. set-ExecutionPolicy RemoteSigned -Scope CurrentUser
  2. Get-ExecutionPolicy
  3. Get-ExecutionPolicy -list
Gorrian answered 23/8, 2021 at 9:45 Comment(1)
This answer doesn't add anything new. Please see the answers that preceded yours.Aguilera
H
1

Go to this link and then follow the steps.

Open Powershell as run as administrator and then run the below commands:

PS> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

PS> Get-ExecutionPolicy

RemoteSigned

PS> .\Start-ActivityTracker.ps1

.\Start-ActivityTracker.ps1 : File .\Start-ActivityTracker.ps1 cannot be loaded.
The file .\Start-ActivityTracker.ps1 is not digitally signed.
The script will not execute on the system.
For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\Start-ActivityTracker.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

PS> Unblock-File -Path [Your Path where the problem found]

PS> Get-ExecutionPolicy

RemoteSigned
Hierodule answered 19/9, 2021 at 7:55 Comment(0)
L
1

To avoid any issue that migt result later

  1. go to your package.json file
  2. change
 "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },

to something like this

"scripts": {
    "start": "node server/app.js",
    "dev": "nodemon server/app.js"
  },

sever here must be the folder your app.js is localted

Leanoraleant answered 12/12, 2022 at 19:7 Comment(0)
T
0

In windows 10.

Mapped wrong path in Adminstration and system variables for npm. Go to Environment variables and change the those path under PATH variables.

Step 1:

C:\Program Files\nodejs\node_modules\npm to C:\Users\Administrator\AppData\Roaming\npm

Step 2:

Then restart my system.

It works fine.

Townsman answered 4/6, 2021 at 1:31 Comment(1)
This doesn't answer the question. At all.Aguilera
E
0

nodemon: File C:\Users\HP\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.

If anyone who facing this problem...so my opinion is that just go in file and delete the nodemon.ps1 file and then try use nodemon filename

Encroach answered 20/6, 2021 at 4:10 Comment(1)
This doesn't add anything new. Please see Adarsh's answer (which preceded yours).Aguilera
G
0

I slove my problem with the following command.

=>run PowerShell as administrator

=>run following command

get-ExecutionPolicy

=>if restricted; run the following command

set-ExecutionPolicy Unrestricted 

=>and set to all

=>again check by foll. command

get-ExecutionPolicy

it will get unrestricted and problem is solved

Genaro answered 7/7, 2021 at 3:26 Comment(1)
This answer doesn't add anything new (please see answers that preceded yours).Aguilera
M
0

This solved mine.

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

and maybe this is more secure as is only restricted to the current user.

Mucky answered 26/8, 2022 at 12:48 Comment(3)
This answer doesn't add anything new.Aguilera
@Aguilera this helped me so i added this answerMucky
"Save yourself some frustration and avoid trying to answer questions which [...] have already been [...] answered many times before." stackoverflow.com/help/how-to-answerAguilera

© 2022 - 2024 — McMap. All rights reserved.