1

首先,我想为拼写错误道歉,我不是很好。

我在启动我的 mern 服务器时遇到问题......我想用“npm run dev”运行它。此命令行执行“npm run server”和“npm run client”。这是我的错误:

C:\Users\Jérémy\Desktop\Rendu\MERN\MERN_d04>npm run dev

mern_d04@1.0.0 dev C:\Users\Jérémy\Desktop\Rendu\MERN\MERN_d04
concurrently "npm run server" "npm run client"

[0] Error occurred when executing command: npm run server
[0] Error: spawn cmd.exe ENOENT
[0]     at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[0]     at onErrorNT (internal/child_process.js:467:16)
[0]     at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] Error occurred when executing command: npm run client
[1] Error: spawn cmd.exe ENOENT
[1]     at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[1]     at onErrorNT (internal/child_process.js:467:16)
[1]     at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] npm run client exited with code -4058
[0] npm run server exited with code -4058
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mern_d04@1.0.0 dev: `concurrently "npm run server" "npm run client"`>npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mern_d04@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!     C:\Users\Jérémy\AppData\Roaming\npm-cache\_logs\2020-04-22T19_45_03_286Z-debug.log

这是我的根 package.json :

{
  "name": "mern_d04",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "client-install": "npm-install --prefix client",
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "concurrently": "^5.1.0",
    "express": "^4.17.1",
    "is-empty": "^1.2.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.9.10",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "validator": "^13.0.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.3"
  }
}

这是我的客户端 package.json :

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "classnames": "^2.2.6",
    "jwt-decode": "^2.2.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-redux": "^7.2.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:5000",
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我尝试了很多东西,最令人惊讶的是:它可以在我朋友的计算机上运行,​​但不能在我的计算机上运行。请问有人可以帮助我吗?:)

编辑:节点版本:13.0.0

编辑:找到解决方案。我“只是”在环境变量中有一个变量“C:\Windows\System32”:)

4

2 回答 2

1

我面临着同样的问题。对于此代码有效,您可以在您的根 package.json 上尝试这个..

"scripts": {
    "start": "node index",
    "server": "nodemon index",
    "client": "npm run start --prefix client",
    "dev": "concurrently \"npm run server\" \"cd client && npm start\""
  },

然后从根目录输入 npm run dev

于 2021-03-10T14:02:03.133 回答
0

node_modules 与您当前的系统不兼容。您可以在客户端级别删除根级别的 node_modules 文件夹。然后你再次安装两个 node_modules。

于 2021-05-16T00:01:10.077 回答