【问题标题】:Trying to run node.js server for some reason it's not accepting my code由于某种原因尝试运行 node.js 服务器它不接受我的代码
【发布时间】:2021-04-05 12:36:38
【问题描述】:

我正在看一个运行 node.js 服务器的教程,我做了与他完全相同的事情,但它不起作用。

这是 package.json:

   {   
      "name": "myserver",
      "version": "1.0.0",
      "description": "form",
      "main": "index.js",
      "scripts":{
        "start":"node index.js",
        "myserver":"nodemon index.js",
        "newtailor":"npm start --prefix newtailor",
        "dev":"concurrently \"npm run myserver\" \"npm run newtailor\""},
        "author": "wes",
        "license": "ISC",
        "dependencies": 
       {"body-parser": "^1.19.0",
         "concurrently": "^5.3.0",
         "cors": "^2.8.5",
         "express": "^4.17.1",
         "nodemailer": "^6.4.17",
         "nodemon": "^2.0.6"}
    }

出现此错误。

npm ERR! JSON.parse "newtailor":"npm...'
npm ERR! JSON. parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

【问题讨论】:

  • 你运行了什么命令?
  • 我拿了这个package.json,它工作正常
  • npm run dev 和 npm start

标签: node.js json npm


【解决方案1】:

我之前在运行较旧的 Node 版本时遇到过这种情况。

据我所知,npm cache clean 提供了帮助。

这是一个有效的 package.json 文件。我在这里测试过:https://jsonformatter.curiousconcept.com/#

{
   "name":"myserver",
   "version":"1.0.0",
   "description":"form",
   "main":"index.js",
   "scripts":{
      "start":"node index.js",
      "myserver":"nodemon index.js",
      "newtailor":"npm start --prefix newtailor",
      "dev":"concurrently \"npm run myserver\" \"npm run newtailor\""
   },
   "author":"wes",
   "license":"ISC",
   "dependencies":{
      "body-parser":"^1.19.0",
      "concurrently":"^5.3.0",
      "cors":"^2.8.5",
      "express":"^4.17.1",
      "nodemailer":"^6.4.17",
      "nodemon":"^2.0.6"
   }
}

【讨论】:

  • 是的,我做了 npm cache clean 还是不行。
  • 很奇怪。我尝试运行 package.json 并没有输出任何解析错误。只是我没有安装任何东西并且文件丢失了。您使用的是什么操作系统以及 npm 版本是什么?
  • 我使用的是Windows10。
  • 只是出于好奇,你能不能尝试创建一个空白项目,执行 npm init -y,添加所有依赖项,然后才添加脚本。
  • 我在运行它时确实创建了一个空白项目给我这个错误。 npm 错误!缺少脚本:开始。然后我插上一切它仍然是一样的。
猜你喜欢
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-08
  • 2021-03-26
  • 2019-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多