启动node.js时无法启动反应应用程序

时间:2017-07-05 19:14:53

标签: javascript node.js reactjs

我正在关注react的教程,最后一步是启动节点,但是当我按照this tutorial的指示执行“npm start”时。我收到了这个错误。

这是错误cmd行给我的起始节点“npm start”

C:\Users\George\Desktop\reactapp>npm start
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\nodejs\\node.exe" "C:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! file C:\Users\George\Desktop\reactapp\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '"' at 11:3
npm ERR!   "keywords": [
npm ERR!   ^
npm ERR! File: C:\Users\George\Desktop\reactapp\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!     C:\Users\George\Desktop\reactapp\npm-debug.log

最后这是我的package.json文件

{
  "name": "reactapp",
  "version": "1.0.0",
  "description": "test react application",
  "main": "index.js",
  "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "start": "node server.js"
    }
}
  "keywords": [
    "test",
    "react",
    "application"
  ],
  "author": "George Louis",
  "license": "ISC",
  "dependencies": {
    "webpack": "^3.0.0"
  }
}

2 个答案:

答案 0 :(得分:0)

您在}"keywoards"之间缺少逗号,而且您有足够的}

您的JSON应该看起来像

  {
    "name": "reactapp",
    "version": "1.0.0",
    "description": "test react application",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "node server.js"
    },
    "keywords": [
        "test",
        "react",
        "application"
    ],
    "author": "George Louis",
    "license": "ISC",
    "dependencies": {
        "webpack": "^3.0.0"
    }
}

答案 1 :(得分:0)

如果您阅读了跟踪,那么npm会告诉您答案

npm ERR! Unexpected token '"' at 11:3
npm ERR!   "keywords": [
npm ERR!   ^
npm ERR! File: C:\Users\George\Desktop\reactapp\package.json

它告诉你什么是错(逗号),哪一行(11)和哪一行(3)哪个文件(C:\Users\George\Desktop\reactapp\package.json)。

所以,你错过了一个逗号:

      "start": "node server.js"
    }
  },
  "keywords": [
    "test",
    "react",
    "application"
  ],

请注意JSON中缺少“关键字”之前的逗号,因此它无效。