You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在package.json中使用concurrently同时运行前后端npm脚本?

Fixing Concurrently to Run MERN Frontend & Backend Together

Let's break down the issues in your current setup and fix them step by step:

1. Fix the client Script in Root package.json

Your current client script has an invalid --suffix flag (likely a typo) that's throwing things off. The correct command to trigger the client's start script from the root project is:

"client": "npm start --prefix client"

The --prefix client tells npm to target the package.json inside your client folder and run its configured start script.

2. Fix the dev Script for Parallel Execution

The biggest mistake here is using &&—this runs commands serially, meaning it waits for the server to finish before trying to start the client. Concurrently is built for parallel runs, so you just need to pass your commands as separate quoted strings, no && needed. Update it to:

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

If your shell supports single quotes, you can simplify it to avoid escaped quotes:

"dev": "concurrently 'npm run server' 'npm run client'"

3. Verify Prerequisites

Before testing, make sure:

  • You've installed concurrently as a dev dependency in your root project:
    npm install --save-dev concurrently
    
  • Your client folder has a valid package.json with a working start script (this is standard if you created the client with Create React App or similar tools).

Full Corrected scripts Section

Here's how your final root package.json scripts should look:

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

Testing It Out

Run the dev script from your root directory:

npm run dev

This should spin up both your backend server (with nodemon for auto-reloads on code changes) and frontend client simultaneously.


内容的提问来源于stack exchange,提问作者Im not Xavier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 12:33:13