You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行index.js报错:系统禁用脚本执行,尝试./index.js 3000无效

解决PowerShell中nodemon执行被阻止的问题

问题描述

PS C:\Users\Leff Tubat\express-demo> nodemon index.js
nodemon : File C:\Users\Leff Tubat\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 index.js
  • + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    

尝试直接执行./index.js 3000也无法解决问题。

解决方案

这是Windows PowerShell的执行策略限制导致的,默认策略不允许运行未经签名的脚本,可按以下方式解决:

  • 以管理员身份打开PowerShell,执行命令修改全局执行策略:

    Set-ExecutionPolicy RemoteSigned
    

    按提示输入Y确认更改,之后重新运行nodemon index.js即可正常启动。

  • 若不想全局修改策略,可临时允许当前会话运行脚本:

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
    

    该设置仅对当前PowerShell会话有效,关闭后自动恢复默认策略。

另外,直接执行./index.js 3000无效是因为Node.js脚本需要通过Node命令启动,正确命令应为:

node index.js 3000

内容的提问来源于stack exchange,提问作者Leff Tubat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 19:32:38