运行nodemon时提示未被识别,寻求有效解决方案
解决
nodemon未被识别的报错问题 报错信息
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 tut69.js
+ CategoryInfo : ObjectNotFound: (nodemon:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
解决方案
全局安装nodemon
打开终端执行全局安装命令:npm install -g nodemon注意:Mac/Linux用户可能需要在命令前加
sudo获取权限;Windows用户建议用管理员身份打开终端执行。检查并配置环境变量
如果已全局安装仍报错,说明npm的全局bin目录未加入系统环境变量:- Windows:找到npm全局bin目录(一般是
C:\Users\[你的用户名]\AppData\Roaming\npm),手动添加到系统PATH环境变量后,重启终端重试。 - Mac/Linux:编辑
~/.bashrc或~/.zshrc文件,添加以下内容:
保存后执行export PATH=$PATH:~/.npm-global/binsource ~/.bashrc(bash终端)或source ~/.zshrc(zsh终端)生效。
- Windows:找到npm全局bin目录(一般是
本地安装并通过npx运行
若不想全局安装,可在项目目录下安装本地依赖:npm install nodemon --save-dev然后用npx直接调用:
npx nodemon tut69.js检查拼写与运行方式
确认命令拼写正确(是nodemon而非nodmon等);若仅本地安装未全局,直接输入nodemon会报错,必须通过npx或项目的npm scripts调用(可在package.json的scripts里添加"start": "nodemon tut69.js",然后执行npm start)。
内容的提问来源于stack exchange,提问作者Sheel Parikh
相关产品推荐
相关产品推荐

