简体   繁体   English

为什么我不能在 mac 上成功运行“npm start”命令?

[英]Why can't I successfully run “npm start” command on mac?

I'm trying to install npm and I keep getting errors.我正在尝试安装 npm 并且我不断收到错误消息。 Initially the problem was I needed a package-lock.json file and package.json file and that was solved by typing "npm init" into the terminal.最初的问题是我需要一个 package-lock.json 文件和 package.json 文件,这可以通过在终端中输入“npm init”来解决。

Then when trying to run "npm start" it said I was missing the start script.然后当试图运行“npm start”时,它说我错过了启动脚本。 So I opened the package.json file to add it as shown below:于是我打开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"
}

Now I'm getting the following errors:现在我收到以下错误:

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

I'm not sure where the error is in the json file or why it can't parse it so if anyone could help point out a solution that would be greatly appreciated.我不确定 json 文件中的错误在哪里,或者为什么它无法解析它,所以如果有人可以帮助指出一个非常感谢的解决方案。

Seems like you're missing a comma in line 7, after "start": "node index.js" .好像您在第 7 行中缺少逗号,在"start": "node index.js"之后。 Here's the correct one:这是正确的:

{
  "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"
}

I recommend you to install an extension for your IDE that can catch syntax errors on JSON files.我建议您为 IDE 安装一个扩展,它可以捕获 JSON 文件上的语法错误。

I suggest you use vscode.我建议你使用 vscode。

It will throw an error when you missing a comma.当您缺少逗号时,它将引发错误。

For example:例如:

the example of missing a comma缺少逗号的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM