I created a React app with npx create-react-app and installed with npm install, then cd'd to correct directory and hit npm start - fine everything working as intended in browser.
I then close the browser and run npm start and get this message:
***** npm start
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\jacma\AppData\Local\npm-cache\_logs\2023-06-29T11_03_32_182Z-debug-0.log
I struggled to find a solution and decided to just start again. Loaded new vs code and repeated initial steps and everything was working fine (specifically npm start). I then closed the tab localhost3000 I was in and tried to run npm start again and got the same error message.
Why am I having an issue with npm start, when I have "start": "react-scripts start" in my scripts in package.json and the command initially works after npx create, but not after it has already run, but works fine after I encountered the issue in a new project?
Any help would be greatly appreciated.
Jake
If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "start" npm error is caused.
If you don't have a package.json file, create one by opening your terminal in your project's root directory and running the command npm init -y.
shell npm init -y