npm start suddenly stops working on react app - reactjs

I've been learning react for about two weeks, when suddenly npm start won't run. This is what I get instead:
sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! recipe-app#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the recipe-app#0.1.0 start 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! /Users/Michelle/.npm/_logs/2020-07-29T14_35_20_988Z-debug.log
After a ton of googling I tried
npm install -g npm#latest but the permission was denied.
Deleted and reinstalled node several times, tried using Homebrew, etc, but nothing worked.
Edit: Found the solution!
Npm couldn't find react-scripts, so I had to change the scripts in package.json to
"start": "node_modules/react-scripts/bin/react-scripts.js start".

You need to install react-scripts
npm install react-scripts

The first line of the logs you just sent indicates your computer doesn't know the command react-scripts.
It means you need to install it.
When you use the -g option with npm install, it means you want to install globally the package, setting the package accessible for every user on your computer. That's why you have a permission error. You can solve this by adding sudo before the command maybe or running it with a elevated user.
It's not mandatory to install the package globally.
I suppose your package.json file contains a script named start starting with react-scripts.
If you install the react-scripts package with npm install react-scripts, you'll find the binary under node_modules/.bin/react-scripts.
Then you can replace in your start script configuration react-scripts with ./node_modules/.bin/react-scripts.
An example of a package.json file:
{
"name": "myapp",
"version": "1.0.0",
...
"scripts": {
...
"start": "./node_modules/.bin/react-scripts [...]",
...
},
...
}

running "npm install react-scripts" even if I had before, worked for me

Related

How do I run Next.js app after cloning repository

I created a Next.js app using npx create-next-app#latest, pushed the new app to a GitHub repository, then cloned the repository into a new directory. When I tried to run the app using npm run dev, I got the following output:
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mini-warehouse#0.1.0 dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mini-warehouse#0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
I was expecting the development server to start. How can I run my app?
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
run : npm install
NOTE : you have always to install node_modules after coloning a repo. because when you push inside a repo the .gitignore file by default ignores node_modules folder because of its size so you should install it by running npm install
the last line from you error stack is telling you the problem
Your projet has an package.json but you didn't install your dependencies
You should install before trying to run you project
running npm install and then npm run dev
https://docs.npmjs.com/cli/v9/configuring-npm/package-json
if you want to know more about package.json

postgrator: not found while migrating postgresql database

Error:
$ heroku run npm run migrate
Running npm run migrate on ⬢ shelly-moth-73910... up, run.3979 (Free)
> noteful-app-server#1.0.0 migrate /app
> postgrator --config postgrator-config.js
sh: 1: postgrator: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! noteful-app-server#1.0.0 migrate: `postgrator --config postgrator-config.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the noteful-app-server#1.0.0 migrate 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! /app/.npm/_logs/2020-09-06T07_52_36_217Z-debug.log
postgrator-cli version 4.0.0 is installed on repo, running npm list postgrator-cli tells me that. But after I push to heroku it's as though postgrator doesn't exist. heroku run npm install postgrator-cli and other such commands don't change, and heroku run npm list postgrator-cli returns:
$ heroku run npm list postgrator-cli
Running npm list postgrator-cli on ⬢ rocky-garden-73910... up, run.7024 (Free)
noteful-app-server#1.0.0 /app
`-- (empty)
Here's my postgrator-config.js
require('dotenv').config();
module.exports = {
'migrationsDirectory': 'migrations',
'driver': 'pg',
'connectionString':
process.env.NODE_ENV === 'test'
? process.env.TEST_DATABASE_URL
: process.env.DATABASE_URL,
'ssl': !!process.env.SSL,
};
Procfile contains web: node src/server.js
I just had the same error.
In my package.json I found that it was in my "devDependencies", not my "dependencies".
When I first installed it, I ran npm i postgrator-cli -D, making it a development dependency. When I tried installing it again without the -D it didn't do anything, so I deleted it from my package.json.
Then, I ran npm i postgrator-cli and checked my package.json and found that it was in my dependencies. I git added, committed, and pushed to heroku and then I ran heroku run npm run migrate - it worked!

Error while running npm run build command in react after installing sass

I installed sass using the command npm install --save-dev sass, while running npm run build command I'm getting the following error
npm ERR! Failed at the react-app#1.1.0 build 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! C:\Users\md3\AppData\Roaming\npm-cache\_logs\2019-11-27T06_26_11_296Z-debug.log
Refer the documentation https://www.npmjs.com/package/sass
Try this npm install -g sass

How to set React app variables in NPM start script

so the npm start in my package.json looks like this
"start": "REACT_APP_Environment=development react-scripts start",
This worked fine for previous developers on the project, possibly because they were on MacOS, that's not the case for me on windows, when I run I get
> REACT_APP_Environment=development react-scripts start
'REACT_APP_Environment' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! enterprise#0.1.0 start: `REACT_APP_Environment=development react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the enterprise#0.1.0 start 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! C:\Users\Omar\AppData\Roaming\npm-cache\_logs\2019-09-22T15_12_59_217Z-debug.log
I can fix this by removing the environment variable from the start script and running by the command set "REACT_APP_Environment=development" && npm start, but this is not convenient, how can I have it all included and work properly on windows in my start script? thanks
I would recommend checking out .env, seems like it might solve your problem
npmjs.com/package/dotenv

create-react-app - react-scripts: command not found

i've just started out with react on codepen, and I really enjoy it! I decided to install it on my MacBook Air. I installed create-react-app using npm, and everything looked good. I then started a project, and everything went smoothly. When I ran npm start, I got an error:
sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! react-app#0.1.0 start: 'react-scripts start'
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the react-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I've come to the conclusion that npm can't find react-scripts. I have done almost everything I have come up with: I have updated npm; I have reinstalled the modules; I have started a new project, but I still get the same error. I've checked, react-scripts is in my node_modules file. The only thing I haven't done is install react-scripts globally, but the creator of create-react-app has said that that is a very bad idea. What should i do?
Just solved the problem:
In package.json, I changed "start": react-scripts start", to "start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start". This solved the problem.
Try running npm install before running npm start, if that doesn't work check out this article on the same issue - sh: react-scripts: command not found after running npm start
Adding the entire path also worked for me:
"start": "node_modules/react-scripts/bin/react-scripts.js start"
instead of just:
"start": "react-scripts start".
I wish I knew why this behavior changed in my pc.
Coincidence or not, I updated my xcode today.
delete package-lock.json:
sudo rm package-lock.json
delete node_modules:
sudo rm -rf node_modules
optionally upgrade npm:
sudo npm install -g npm
and install project again
npm i
run project:
npm start
worked for me in the situation like you described

Resources