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

请求解决VS Code终端中nodemon无法运行的问题

问题描述

已通过npm i nodemon成功安装nodemon,但在VS Code的PowerShell终端执行nodemon命令时提示未识别,终端报错信息如下:

PS D:\my-express-server> npm i nodemon

added 32 packages, and audited 90 packages in 6s

10 packages are looking for funding
  run `npm fund` for details
found 0 vulnerabilities
PS D:\my-express-server> nodemon -v
nodemon : The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,        
verify that the path is correct and try again.
At line:1 char:1
+ nodemon -v
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (nodemon:String) [], CommandNotFoundException

PS D:\my-express-server> nodemon .\server.js
nodemon : The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,        
verify that the path is correct and try again.
At line:1 char:1
+ nodemon .\server.js
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (nodemon:String) [], CommandNotFoundException

解决方案

  • 用npx直接调用本地包
    本地安装的nodemon未加入系统PATH,可通过npx直接调用项目内的nodemon:

    npx nodemon .\server.js
    
  • 在package.json中配置启动脚本
    打开项目的package.json,在scripts字段添加启动命令:

    {
      "scripts": {
        "dev": "nodemon server.js"
      }
    }
    

    之后在终端执行:

    npm run dev
    
  • 全局安装nodemon
    若需要在任意终端直接使用nodemon命令,执行全局安装:

    npm install -g nodemon
    

    安装完成后重启VS Code终端,再执行nodemon -v验证是否生效。

  • 调整PowerShell执行策略(全局安装后仍报错时)
    以管理员身份打开VS Code终端,执行命令修改执行策略:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    

    按提示输入Y确认,重启终端后重试nodemon命令。

内容的提问来源于stack exchange,提问作者Amit Kumar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 05:05:19