【问题标题】:npm concurrently error? when running both frontend and backend together?npm 并发错误?当同时运行前端和后端时?
【发布时间】:2021-05-03 16:36:10
【问题描述】:
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "server": "nodemon backend/server.js",
    "client": "npm start --prefix frontend",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  }

这是我的 package.json 文件的脚本,它位于前端和后端文件夹之外(在根文件夹中)。当我运行命令npm run dev 时,由于某种原因它不起作用。请注意npm run servernpm run client 可以正常工作,但问题是当我运行其中包含concurrently 的命令npm run dev 时,我不知道是什么问题,有什么办法可以解决这个问题?这是我收到的错误消息:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ecommerce_shop@1.0.0 dev: `concurrently "npm run server" "npm run client"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ecommerce_shop@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2021-01-29T18_24_43_756Z-debug.log

【问题讨论】:

  • 您是否尝试从终端运行命令?也尝试以这种方式运行它npm run server && npm run client
  • 正如我提到的 npm run servernpm run client 在单独执行时工作得很好,但是当我运行 npm run dev(其中包含 concurrently)时它不起作用,所以我猜猜concurrently一定有问题吧?
  • 我不确定concurrently 是什么我认为它同时运行,现在如果客户端依赖于可能导致问题的服务器。
  • 列出的日志文件中是否有任何内容暴露了更具体的错误?如果您的客户端依赖于服务器来启动,如果它恰好在服务器之前启动,它可能会立即退出。
  • 好吧,如果我不运行服务器,客户端仍然会启动但无法获取数据

标签: node.js reactjs react-native express npm


【解决方案1】:

通常,npm ELIFECYCLE 错误意味着你的 npm 项目安装已损坏。

尝试以下,取自另一个SO question

  1. 运行npm cache clean --force
  2. 删除node_modules文件夹
  3. 删除package-lock.json文件
  4. npm install

另外,为了确保您使用的是本地安装中的concurrently,而不是全局安装,我建议将npx 附加到它:

    "dev": "npx concurrently \"npm run server\" \"npm run client\""

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 2019-06-29
    • 1970-01-01
    • 2018-03-11
    • 2023-02-17
    • 2022-10-17
    • 2020-07-17
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多