npm concurrently error? when running both frontend and backend together?
Asked Answered
C

2

8
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "server": "nodemon backend/server.js",
    "client": "npm start --prefix frontend",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  }

here's my scripts for the package.json file that's outside the frontend and backend folders (in the root folder). and when I run the command npm run dev it doesn't work for some reason. note that npm run server and npm run client work prefectly but the issue is when I run the command npm run dev which has the concurrently in it, I don't know what's the issue, is there something I can do to fix this? here's the error message that I get:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `concurrently "npm run server" "npm run client"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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!     /home/user/.npm/_logs/2021-01-29T18_24_43_756Z-debug.log

Crackling answered 29/1, 2021 at 18:28 Comment(6)
Did you try running the command from the terminal? also try running it this way npm run server && npm run clientHearn
as I mentioned both npm run server and npm run client work just fine when executed separately, but when I run the npm run dev (which contains the concurrently) it doesn't work, So I guess there must be a problem with concurrently right?Crackling
I'm not sure what concurrently does I assume it runs both simultaneously, now if client is dependent on the server that might cause the issue.Hearn
Is there anything in the log file listed that exposes a more specific error? It’s possible if your client depends on the server to start that it is just exiting immediately if it happens to start before the server.Roland
well if I don't run the server, the client still launches but fails to fetch dataCrackling
@ToddRylaarsdam well, I tried, but still got the same error. I think the problem is with concurrently or npm but don't know what it is. I use the same scripts for my other projects but they work just fine, I don't know what I'm doing wrong now.Crackling
C
0

Usually, npm ELIFECYCLE error means that your npm project installation is corrupted.

Try the following, taken from this other SO question:

  1. Run npm cache clean --force or
  2. delete node_modules folder
  3. delete package-lock.json file
  4. npm install

Also to make sure you are using concurrently from your local installation and not your global one, I suggest appending npx to it:

    "dev": "npx concurrently \"npm run server\" \"npm run client\""
Counterpressure answered 23/2, 2021 at 20:33 Comment(0)
F
-1

"dev": "concurrently "npm run server" "cd ../Frontend && npm run client""

cd is compulsory

Fidel answered 23/9 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.