【问题标题】:npm start gives an errornpm start 报错
【发布时间】:2017-03-11 11:47:29
【问题描述】:

我已经通过 npm 安装了不同的包来在 React 中运行一个简单的 hello world 应用程序(我是新手)。安装后,package.json 具有这种格式。

{
  "name": "test",
  "version": "1.0.0",
  "description": "test",
  "main": "index.js"
},
  "repository": {
  "type": "git",
  "url": "https://github.com/theo82"
},
  "keywords": [
  "test"
],
 "author": "Theo Tziomakas",
 "license": "ISC",
 "dependencies": {
 "react": "^15.4.2",
 "react-dom": "^15.4.2",
 "webpack": "^2.2.1"
  }
}

在 cmd(windows 8.1) 中运行 npm start 后,出现此错误。

 npm ERR! Unexpected token ',' at 6:4
 npm ERR!   },
 npm ERR!    ^

在各种答案中,人们通过使用干净的缓存解决了这个问题

npm cache clean

但是,这对我不起作用:(。任何想法为什么会发生这种情况?

谢谢,

西奥。

【问题讨论】:

  • 语法错误

标签: node.js reactjs npm


【解决方案1】:

您的文件中有语法错误。你也应该指定你的start 脚本应该做什么。例如,当你运行npm start时节点应该执行index.js文件

{
  "name": "test",
  "version": "1.0.0",
  "description": "test",
  "main": "index.js",
  "scripts": {
    "start": "node index.js" 
  },
  "keywords": [
    "test"
  ],
  "author": "",
  "license": "ISC"
}

【讨论】:

  • 感谢您阅读我的问题。但是,您的答案不起作用。
  • 你确定你的根目录下有 index.js 文件吗? start 脚本不是 npm 的一些默认脚本。 start 脚本可以是你想要的任何东西。在我的示例中,它在根目录中执行 index.js 文件
【解决方案2】:

你的package.json的语法有问题,在main键的那一行后面多了一个}

{
  "name": "test",
  "version": "1.0.0",
  "description": "test",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/theo82"
   },
  "keywords": [
    "test"
  ],
 "author": "Theo Tziomakas",
 "license": "ISC",
 "dependencies": {
   "react": "^15.4.2",
   "react-dom": "^15.4.2",
   "webpack": "^2.2.1"
  }
}

【讨论】:

    猜你喜欢
    • 2018-02-10
    • 2022-09-27
    • 2022-12-04
    • 2021-04-19
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    相关资源
    最近更新 更多