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

nodemon无法运行,附使用提示及package.json配置求助

解决nodemon运行报错的问题

你遇到的报错是因为没有正确配置启动脚本,且直接调用本地安装的nodemon时未指定目标文件,结合你的package.json配置,按以下步骤解决:

步骤1:添加启动脚本到package.json

在scripts字段中添加一个dev(或start)命令,指定nodemon要运行的入口文件(你的项目入口是index.js):

{
  "name": "nodeserver",
  "version": "1.0.0",
  "description": "This is a node Server for LetsChat Application",
  "main": "index.js",
  "scripts": { 
    "dev": "nodemon index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "neetu",
  "license": "ISC",
  "dependencies": {
    "socket.io": "^2.3.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.4"
  }
}

注意:我把nodemon移到了devDependencies里——nodemon是开发阶段用来自动重启服务的工具,不需要打包到生产环境,所以更适合放在devDependencies中。如果之前是装在dependencies里,你可以执行npm uninstall nodemon --save && npm install nodemon --save-dev来调整。

步骤2:正确启动服务

之后不要再直接敲nodemon命令,而是通过npm运行脚本:

npm run dev

这样npm会自动找到node_modules/.bin目录下的nodemon执行文件,并按照脚本里的配置运行index.js,就不会再出现参数错误的提示了。

额外说明

如果一定要直接执行nodemon,需要明确指定要运行的文件,比如:

npx nodemon index.js

npx会帮你找到本地安装的nodemon并执行,但还是推荐用npm scripts的方式,更规范且便于团队协作。

内容的提问来源于stack exchange,提问作者neetu gangawane

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 06:16:17