【问题标题】:Why can't I successfully run "npm start" command on mac?为什么我不能在 mac 上成功运行“npm start”命令?
【发布时间】:2020-07-24 16:30:47
【问题描述】:

我正在尝试安装 npm,但我不断收到错误消息。最初的问题是我需要一个 package-lock.json 文件和 package.json 文件,这可以通过在终端中输入“npm init”来解决。

然后当尝试运行“npm start”时,它说我缺少启动脚本。于是我打开package.json文件添加如下:

{
  "name": "arvinder",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

现在我收到以下错误:

Arvinders-MacBook-Air:~ Arvinder$ npm start
npm ERR! file /Users/Arvinder/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 137 while parsing '{
npm ERR! JSON.parse   "name": "arvinder",
npm ERR! JSON.parse   "version": "1.'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Arvinder/.npm/_logs/2020-07-24T16_26_18_155Z-debug.log

我不确定 json 文件中的错误在哪里,或者为什么它无法解析它,所以如果有人能帮助指出一个解决方案,将不胜感激。

【问题讨论】:

    标签: node.js json npm


    【解决方案1】:

    在第 7 行中,"start": "node index.js" 之后似乎缺少逗号。这是正确的:

    {
      "name": "arvinder",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "start": "node index.js",
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC"
    }
    

    我建议您为您的 IDE 安装一个可以捕获 JSON 文件语法错误的扩展。

    【讨论】:

      【解决方案2】:

      我建议你使用 vscode。

      缺少逗号时会抛出错误。

      例如:

      the example of missing a comma

      【讨论】:

        猜你喜欢
        • 2020-11-15
        • 2014-11-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-29
        • 1970-01-01
        • 1970-01-01
        • 2019-03-21
        相关资源
        最近更新 更多