简体   繁体   中英

Concurrently issues running node using MERN

I am having issues when running node server. I am working on application using MERN. I have followed steps and edited my root package.json. But following is the error i am getting after running command: npm run dev.

> mern-shopping-cart@1.0.0 dev E:\Tanmay\Redux\mern-shopping-cart
> concurrently "npm run server" "cd frontend && npm start"

[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:469:16)
[0]     at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] Error occurred when executing command: cd frontend && npm start
[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:469:16)
[1]     at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] cd frontend && npm start exited with code -4058
[0] npm run server exited with code -4058

Here is my root package.json

{
  "name": "mern-shopping-cart",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "start": "node backend/server.js",
    "server": "nodemon backend/server.js",
    "client": "npm start --prefix frontend",
    "dev": "concurrently \"npm run server\" \"cd frontend && npm start\""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "mongoose": "^5.12.5"
  },
  "devDependencies": {
    "concurrently": "^6.0.2",
    "nodemon": "^2.0.7"
  }
}

So i have figured out a solution which runs the nodejs and frontend project concurrently on the same port. All i had to go is:

  1. Go to Environment variables where you would find it from the control panel (wont be posting the entire path, you can google it by yourself for Environment variables)
  2. Add the PATH under the System variables
  3. Add this to the path: C:\Windows\System32\
  4. RESTART your system for the latest changes.

Posted this answer as it might help someone in the future looking for the answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM