首页 > 解决方案 > 通过 cmd 使用“并发”来测试 API,但我收到错误

问题描述

我是初学者学习 React js。我已经实现了一个 REST API ( https://jsonplaceholder.typicode.com/ )

我使用“并发”使用“npm run start:dev”同时运行两个脚本,但是在执行此操作时出现错误。

下面给出的是我的 package.json 文件

     {
      "name": "myproj",
      
      "version": "0.1.0",
    
      "private": true,
    
      "dependencies": 
    
    {
        "@testing-library/jest-dom": "^5.11.4",
    
        "@testing-library/react": "^11.1.0",
        "@testing-library/user-event": "^12.1.10",
        "axios": "^0.21.1",
        "bootstrap": "^4.6.0",
        "json-server": "^0.16.3",
        "react": "^17.0.1",
        "react-dom": "^17.0.1",
        "react-router-dom": "^5.2.0",
        "react-scripts": "4.0.2",
        "web-vitals": "^1.0.1"
      }
    
      "scripts": 
    {
        "start": "react-scripts start",
    
        "json-server": "json-server --watch db.json --port 3001",
    
        "start:dev": "concurrently \"npm start\" \"npm run json-server\"",
    
        "build": "react-scripts build",
    
        "test": "react-scripts test",
    
        "eject": "react-scripts eject"
    },
    
      "eslintConfig": 
     {
      
      "extends": 
       [
          "react-app",
          "react-app/jest"
        ]
    
      },
    
    
      "browserslist":
     {
       
     "production": 
      [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
    
        "development": 
       [
    
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      }
    }

我得到的错误

D:\FirstReact\myproj>npm start 

> myproj@0.1.0 start D:\FirstReact\myproj
 
>concurrently "npm start" "npm run json-server"  

code ELIFECYCLE
npm ERR! errno 1                                                                             
npm ERR! myproj@0.1.0 start: `react-scripts start:`concurrently "npm run json- server"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myproj@0.1.0 start 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! C:\Users\Sony\AppData\Roaming\npm-cache\_logs\2021-02-24T13_50_08_231Z-debug.log

请告诉我如何解决此错误

这是错误错误图像的图像

这是我的项目结构的图像我的项目结构

标签: node.jsreactjsconcurrency

解决方案


推荐阅读