node .js -启动命令使节点崩溃,但index.js运行正常

Node.js - start command crashing node, but index.js running fine

本文关键字:js index 运行 节点 启动 命令 node 崩溃      更新时间:2023-09-26

我有一个node.js包,其中index.js文件按预期工作。

但是当我调用

npm start

出现以下错误导致崩溃:

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v4.6.0
npm ERR! npm  v2.15.9
npm ERR! file /Users/martin.mcallister/Documents/leftovers/package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Trailing comma in object at 24:1
npm ERR! }
npm ERR! ^
npm ERR! File: /Users/martin.mcallister/Documents/leftovers/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! Please include the following file with any support request:
npm ERR!     /Users/martin.mcallister/Documents/leftovers/npm-debug.log
我已经检查过包裹了。json文件。没有评论。据我所见,没有错误。
{
  "name": "leftovers",
  "version": "1.0.0",
  "description": "Use your leftovers",
  "main": "index.js",
  "scripts": {
    "start" : "node index.js",
    "test": "echo '"Error: no test specified'" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/niazipan/leftovers.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/niazipan/leftovers/issues"
  },
  "homepage": "https://github.com/niazipan/leftovers#readme",
  "dependencies": {
    "body-parser": "^1.15.2",
    "express": "^4.14.0"
  },
}

即使我从json中删除开始行并运行npm start,它仍然会在顶部出现错误而崩溃。

任何想法吗?

检查你的错误老兄,它说它不能解析你的包。

{
  "name": "leftovers",
  "version": "1.0.0",
  "description": "Use your leftovers",
  "main": "index.js",
  "scripts": {
    "start" : "node index.js",
    "test": "echo '"Error: no test specified'" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/niazipan/leftovers.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/niazipan/leftovers/issues"
  },
  "homepage": "https://github.com/niazipan/leftovers#readme",
  "dependencies": {
    "body-parser": "^1.15.2",
    "express": "^4.14.0"
  },
}

最后一行前的逗号构成您的包。Json文件无效