请求解决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
相关产品推荐
相关产品推荐

