So, I've tried running npm i
on my React app so that I can work concurrently on both front and back end at the same time. However, it seems to be hanging on the "install":
[email protected] install
cd server && npm i && cd ../client && npm i
Below are the package.json
scripts I'm using:
"scripts": {
"start": "node server/server.js",
"dev": "concurrently \"cd server && npm run watch\" \"cd client && npm start\"",
"install": "cd server && npm i && cd ../client && npm i",
"build": "cd client && npm run build",
"seed": "cd server && npm run seed",
"test": "echo \"Error: no test specified.\" && exit 1",
"eject": "react-scripts eject"
},
What am I doing wrong? Any help is greatly appreciated!
CodePudding user response:
You may be running into an infinite loop since you have defined an install
script in your package.json
. For more details on npm scripts
configuration have a look here.
You might also be facing similar issues with some of the other scripts you have defined, e.g. build
also calls itself npm run build
. You should build the project code as part of the build
script. See the CRA source build script for reference: https://github.com/facebook/create-react-app/blob/d960b9e38c062584ff6cfb1a70e1512509a966e7/package.json#L8
Try removing the install
script and run the commands manually when you need to install dependencies for your project. The updated scripts:
"scripts": {
"start": "node server/server.js",
"dev": "concurrently \"cd server && npm run watch\" \"cd client && npm start",
"build": "cd client && npm run build",
"seed": "cd server && npm run seed",
"test": "echo \"Error: no test specified\" && exit 1",
"eject": "react-scripts eject"
},
As a side note/question, why don't you run npm i
from the root of the project and then run your build
and seed
commands?
Only installing dependencies will not build your app, in most cases.