简体   繁体   English

如何修复错误 - nodemon.ps1 无法加载,因为在此系统上禁用了运行脚本(没有安全风险)?

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

Error on terminal: nodemon.ps1 cannot be loaded because running scripts is disabled on this system.终端错误:无法加载nodemon.ps1 ,因为在此系统上禁用了运行脚本。 For more information, see about_Execution_Policies at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2有关详细信息,请参阅https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2上的about_Execution_Policies

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 .目标是使用nodemon

I'd recommend using RemoteSigned as opposed to Unrestricted , and limiting the policy to the CurrentUser if possible.我建议使用RemoteSigned而不是Unrestricted ,并尽可能将策略限制为CurrentUser

Run Powershell as Admin, and then:以管理员身份运行 Powershell,然后:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

RemoteSigned : "The default execution policy for Windows server computers." RemoteSigned :“Windows 服务器计算机的默认执行策略。”



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." “执行策略不是限制用户操作的安全系统。例如,当用户无法运行脚本时,可以通过在命令行键入脚本内容轻松绕过策略。相反,执行策略帮助用户设置基本并防止他们无意中违反规则。”

For those who are not aware of how to solve this error using Windows PowerShell对于那些不知道如何使用 Windows PowerShell 解决此错误的人

  1. Open PowerShell (Run As Administrator)打开 PowerShell(以管理员身份运行)
  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
    nodemon 'filename.js'

Hope this would be helpful希望这会有所帮助

Step 1: Go to this location --> File C:\Users\Dell\AppData\Roaming\npm第 1 步:Go 到此位置 --> 文件 C:\Users\Dell\AppData\Roaming\npm
Step 2: Delete the nodemon.ps1 file and run the command.步骤 2:删除 nodemon.ps1 文件并运行命令。

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 ie scripts written by you while scripts from a remote source (nodemon in this case) must be signed by a trusted authority.这基本上意味着您可以执行本地未签名的脚本,即由您编写的脚本,而来自远程源(在本例中为 nodemon)的脚本必须由受信任的机构签名。

PS: 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 PS:如果您在 windows 上,您只需 go 到设置 >> 更新和安全 >> 开发人员 >> 选中change execution policy to allow local powershell scripts to run without signing

This command might help此命令可能会有所帮助

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

While using npm I recommend to bridge the nodemon command in the scripts section and leave the security settings as they are.在使用 npm 时,我建议在scripts部分桥接 nodemon 命令并保留安全设置。

package.json: 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.只需执行npm run nodemon hmr它将在后台运行 hmr 行。

I've a better solution, just go to the folder where nodemon.ps1 places (path is in error) and delete nodemon.ps1 file.我有一个更好的解决方案,只需 go 到nodemon.ps1所在的文件夹(路径错误)并删除nodemon.ps1文件。

now go to the terminal and run nodemon -v , if you get a version then the problem solved.现在 go 到终端并运行nodemon -v ,如果你得到一个版本,那么问题就解决了。

You can do this by without changing the policy.您可以在不更改策略的情况下执行此操作。 C:\Users\HP MICROTECH\AppData\Roaming\npm\nodemon.ps1 (path is given at error screen) C:\Users\HP MICROTECH\AppData\Roaming\npm\nodemon.ps1(路径在错误屏幕上给出)

just go to this path and delete nodemon.ps1只需 go 到此路径并删除 nodemon.ps1

and there your nodemon runs.你的nodemon在那里运行。

This cmd works properly.这个 cmd 工作正常。

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

The best way to get rid of this error is摆脱这个错误的最好方法是
Run the below command in your windows power shell as admin以管理员身份在 windows 电源 shell 中运行以下命令

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Basically it will ask you to change the execution policy then type Y.基本上它会要求您更改执行策略,然后键入 Y。

                  **OR**

You can do is without changing your execution Policy你可以做的是不改变你的执行策略

  1. Install nodemon using this command: npm i nodemon -g使用以下命令安装 nodemon: 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.然后键入 nodemon -v 您将在错误 go 的第一行中看到该路径的路径,然后删除该 nodemon.ps1 文件或扩展名为 .ps1xml 的文件名。

Make sure that you are installing nodemon globally For more details microsoft execution policies docs确保您正在全局安装 nodemon 有关更多详细信息microsoft 执行策略文档

Go to the folder: - C:\Users\admin\AppData\Roaming\npm Go 到文件夹: - C:\Users\admin\AppData\Roaming\npm

Delete the powershell file of nodemon or nodemon.ps1.删除nodemon或nodemon.ps1的powershell文件。 You will be good to go.你会对 go 很好。

Go to this link and then follow the steps. Go 到此链接,然后按照步骤操作。

Open Powershell as run as administrator and then run the below commands:以管理员身份打开 Powershell,然后运行以下命令:

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

Faced Similar issue while running some node command.运行某些节点命令时遇到类似问题。 AppData\Roaming\npm\serverless.ps1 cannot be loaded because running scripts is disabled on this system.无法加载 AppData\Roaming\npm\serverless.ps1,因为在此系统上禁用了运行脚本。

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 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

In windows 10.在 windows 10.

Mapped wrong path in Adminstration and system variables for npm.在 npm 的管理和系统变量中映射了错误的路径。 Go to Environment variables and change the those path under PATH variables. Go 到环境变量并更改PATH变量下的那些路径。

Step 1:步骤1:

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

Step 2:第2步:

Then restart my system.然后重新启动我的系统。

It works fine.它工作正常。

nodemon: File C:\Users\HP\AppData\Roaming\npm\nodemon.ps1 cannot be loaded because running scripts is disabled on this system. nodemon:文件 C:\Users\HP\AppData\Roaming\npm\nodemon.ps1 无法加载,因为在此系统上禁用了运行脚本。 For more更多
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.有关信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 上的 about_Execution_Policies。

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如果有人遇到这个问题......所以我的意见是文件中只有 go 并删除 nodemon.ps1 文件,然后尝试使用 nodemon 文件名

I slove my problem with the following command.我用以下命令解决了我的问题。

=>run PowerShell as administrator =>以管理员身份运行 PowerShell

=>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它将不受限制并且问题得到解决

Run these commands:运行这些命令:

  1. set-ExecutionPolicy RemoteSigned -Scope CurrentUser set-ExecutionPolicy RemoteSigned -Scope CurrentUser
  2. Get-ExecutionPolicy获取执行策略
  3. Get-ExecutionPolicy -list获取执行策略列表

This solved mine.这解决了我的问题。

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

and maybe this is more secure as is only restricted to the current user.也许这更安全,因为仅限于当前用户。

On WIN 10在赢得 10

  • Open Windows PowerShell (Run as Administrator)打开 Windows PowerShell(以管理员身份运行)

Run following command运行以下命令

  • Get-ExecutionPolicy获取执行策略
  • Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser Set-ExecutionPolicy -ExecutionPolicy 未定义 -Scope CurrentUser

Reference: Click [here](https: https://docs.microsoft.com/id-id/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2参考:点击[这里](https: https://docs.microsoft.com/id-id/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM