【问题标题】:Can't start client and server together with concurrently无法同时启动客户端和服务器
【发布时间】:2019-10-30 15:26:06
【问题描述】:

index.js: const port = process.env.PORT || 3000;

服务器包.json:

    "start": "node index.js",
    "server": "nodemon index.js",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },

客户端包.json:

"proxy": "http://localhost:5000",

我从npm run dev开始

知道问题出在哪里吗?

错误:

Error: Cannot find module '.../index.js'

【问题讨论】:

  • 让我们看看你的文件夹结构?现在我要猜测一下,告诉你试试../../index.js
  • 文件夹结构是:主文件夹:项目和内部客户端文件夹(用于反应)和 index.js 所在的 src 文件夹(服务器)
  • 子路径中有客户端或服务器吗?如果是,您需要在命令定义处运行“cd &&”
  • 子路径是什么意思?我不太明白我需要做什么?
  • 我会写一个回答,你会明白的,等等...

标签: node.js reactjs concurrently


【解决方案1】:

尝试映射客户端项目的子路径:

{
    "start": "node index.js",
    "server": "nodemon index.js",
    "client": "cd client && npm start",
    "dev": "concurrently \"npm run server\" \"npm run client\""
},

【讨论】:

    【解决方案2】:

    因为我有 applicationserver 文件夹,所以出现了同样的问题。我通过给出路径解决了它 --> "application": "cd ../ && npm start --prefix application"

    {
      "server": "nodemon server/app.js",
      "application": "cd ../ && npm start --prefix application",
      "dev": "concurrently \"npm run server\"  \"npm run application\" "
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 2012-10-25
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      • 2015-10-23
      • 1970-01-01
      相关资源
      最近更新 更多