Docker > Building Images > Exposing Ports: error message sh: react-scripts: command not found

I’m using a MacBook Pro (2016) model running iTerm2. Here’s the issue in iTerm2:

react-app@0.1.0 start
react-scripts start

sh: react-scripts: command not found
aarongayah@A1ryanGs-MacBook-Pro section4-react-app %

I used the same code shown in the lesson. I had the same issue when using a Lenovo Laptop running Windows 11 which is why I’m using my MacBook Pro now. ChatGPT is advising the following, none of which are working:

The error message sh: react-scripts: command not found indicates that the system cannot find the react-scripts package, which is essential for running the development server for your React app.

Step 1: Check package.json

Make sure you have a package.json file in your section4-react-app directory and that it contains react-scripts in the "dependencies" section.

Your package.json should look something like this:

jsonCopy code

  "name": "react-app",
  "version": "0.1.0",
  "dependencies": {
    "react": "^xx.x.x",
    "react-dom": "^xx.x.x",
    "react-scripts": "x.x.x"
  "scripts": {
    "start": "react-scripts start"

Step 2: Reinstall Node Modules

Sometimes the node_modules folder can become corrupt or miss packages.

Delete your node_modules folder and package-lock.json file, and then reinstall your project dependencies.

bashCopy code

rm -rf node_modules package-lock.json
npm install

Step 3: Run npm start Again

After you’ve reinstalled your node_modules, try running npm start again.

bashCopy code

npm start

Step 4: Use npx

If it’s still not working, try using npx to run react-scripts directly.

bashCopy code

npx react-scripts start

Step 5: Check Global Installation

Ensure that you haven’t installed react-scripts globally, which could cause conflicts. If you have, you might want to uninstall the global package:

bashCopy code

npm uninstall -g react-scripts

Then, navigate back to your project directory and reinstall the local package:

bashCopy code

cd path/to/section4-react-app
npm install react-scripts

The problem was not resolved. Please advise. I’ve spent three days trying to get past this bit to no avail.

I figured out the problem. Adding the user/group/etc caused the code to break. Everything worked only after I removed those lines of code. It meant that I was the root user by default, but I could not find anything to resolve that issue.

ChatGPT was prompting to reinstall npm, etc, none of which worked on Windows or Mac.