npm start produces error in React app on WebStorm - reactjs

I see the question has been asked before but none of the solutions seems to help me.
Error that I am getting, I tried to remove the node_modules directory as well. And then reinstalled npm. Still the same error.
rm -rf node_modules
npm install
npm start
-- same error
Even tried deleting the package-lock.json, but same error on npm start.
Node version - v10.15.3
NPM version - 6.4.1
Aryans-MacBook-Pro:react-new-app aryanarora$ npm start
> react-new-app#0.1.0 start /Users/aryanarora/Desktop/The Web Developer Bootcamp/01 All Practice Files /js<:>/Jon Duckett/react-new-app
> react-scripts start
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-new-app#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the react-new-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/aryanarora/.npm/_logs/2019-04-29T06_08_07_273Z-debug.log
After doing npm list --depth 0 | grep react-scripts
output as follows:
Aryans-MacBook-Pro:react-new-app aryanarora$ npm list --depth 0 | grep react-scripts
└── react-scripts#3.0.0
npm ERR! peer dep missing: typescript#*, required by #typescript-eslint/eslint-plugin#1.6.0
npm ERR! peer dep missing: typescript#*, required by #typescript-eslint/parser#1.6.0
npm ERR! peer dep missing: typescript#*, required by #typescript-eslint/parser#1.6.0
npm ERR! peer dep missing: typescript#*, required by #typescript-eslint/typescript-estree#1.6.0
npm ERR! peer dep missing: typescript#>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev, required by tsutils#3.10.0
npm ERR! peer dep missing: typescript#*, required by #typescript-eslint/typescript-estree#1.6.0
npm ERR! peer dep missing: typescript#*, required by ts-pnp#1.1.2
Package.json File
{
"name": "react-new-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Please make sure React-scripts node module installed, to check this, please do below steps.
install npm install again
Go to node_modules --> react-scripts (make sure folder exists)
Run npm start

It may be the issue of npm version. Please try some suggestions.
Uninstall yarn npm uninstall -g yarn
Do a cache clean. npm cache clean -f
If still doesn't work, try to downgrade/upgrade your npm version to npm 5.4.2 or npm 5.3.*.
npm install -g npm#5.4.2

The problem could be the node and npm itself.
Try to uninstall node from your machine completely by using Homebrew or NVM, whichever you used to install node. Else you have to do it manually.
Follow the steps in this link - https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/
Next install the LTS node from the official website (https://nodejs.org/en/), this should solve the issue.
One thing i also found out to be helpful was to change the directory. My directory had folder named "</>js" which I beleive created some issues.

Related

Npm start is not working when trying to relaunch a react app

I've already launched the project using npx create-react-app. The app opened up in my browser and everything was going great. My computer restarted overnight, and the browser tab hosting the app was closed. I'm trying to re launch the app using "npm start" in the terminal, but I am getting the following error:
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! /Users/guaclim/.npm/_logs/2023-01-31T15_34_16_068Z-debug-0.log
Npm start worked just fine when it came to launching the app the first time. I've tried updating and reinstalling npm. My json is also as it should be as far as I can tell :
"name": "new-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I also attempted the following steps but it looks like there was an authorization issue:
npm install -g npm#latest -- to update npm because it is sometimes buggy.
rm -rf node_modules -- to remove the existing modules.
npm install -- to re-install the project dependencies.
The errors i got:
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! dest /usr/local/lib/node_modules/.npm-i9nnxROI
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/lib/node_modules/npm',
npm ERR! dest: '/usr/local/lib/node_modules/.npm-i9nnxROI'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

Eslint in React not correcting errors

I am working on a project that runs on node 10, "react": "^17.0.1".
"react-scripts": "^4.0.1",
On each project start is shows many warnings, for example usage o == instead of ===, etc.
Here is part of the scripts, start original, the other 3 added by me trying to find a solution:
"scripts": {
"start": "env-cmd -f .env.dev --use-shell \"react-scripts start\"",
"lint": "eslint src --ext .js,.jsx",
"lint:fix": "npm run lint -- --fix",
"eslint": "eslint \"src/**/*.{js,jsx}\" --fix"
},
I wanted to run eslint to automatically fix warnings. I tried the commands:
eslint "src/**/*.{js,jsx}" --fix
npm run eslint;
npm run lint
No matter what command I run I get such error message:
✖ 312 problems (3 errors, 309 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! company#1.0.0 lint: `eslint src --ext .js,.jsx`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the company#1.0.0 lint 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/myname/.npm/_logs/2022-04-14T12_48_51_948Z-debug.log
Or:
✖ 312 problems (3 errors, 309 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! company#1.0.0 lint: `eslint src --ext .js,.jsx "--fix"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the company#1.0.0 lint 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/myname/.npm/_logs/2022-04-14T12_57_18_764Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! company#1.0.0 lint:fix: `npm run lint -- --fix`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the company#1.0.0 lint:fix 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/myname/.npm/_logs/2022-04-14T12_57_18_794Z-debug.log
in the package.json there is this info:
"eslintConfig": {
"extends": [
"react-app"
]
},
No eslink packages installed in package.json - is should be using the react-scripts embedded eslint.
Does anybody have a clue how to make eslint fix a plenty of warnings nobody cared about?
EDIT:
Maybe this error appears after the list of warning, because in the middle there are also few errors such as:
here path to the file
10:41 error React Hook "useState" is called in function "betaBanner" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter react-hooks/rules-of-hooks
EDIT 2:
Yes, after I manually corrected the two errors it now writes in yellow ✖ 309 problems (0 errors, 309 warnings) and the error at the end disappeared.
Sometimes reinstalling the node_modules fixes such issues for me.
These are the steps I follow:
Clean npm cache : npm cache clean --force
Delete the node_modules folder and package-lock.json file.
Do a fresh package install : npm install
Start project : npm start
For VS Code, you can try adding these settings in your VS Code settings.json
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.tslint": true,
"source.fixAll.stylelint": true
},
Add this config to your .eslintrc configuration file
"react-hooks/exhaustive-deps": [
"warn",
{
"enableDangerousAutofixThisMayCauseInfiniteLoops": true
}
]
Read more about the issue here https://github.com/facebook/react/issues/18235#issuecomment-898636301

can someone help me with difficulties installing react-scripts? It leads to many error msgs I don't understand

I am trying to npm install and running into dependency issues. The goal is to npm start and npm run build both of which were disrupted somehow.
This is among my first experiences handling dependency issues. The ideal answer includes the thought process one might use to address such a task, if possible, but it is just a bonus.
The root of the problem is that npm start gives me:
> postmassiv#0.1.0 start
> react-scripts start
'react-scripts' is not recognized as an internal or external command,
operable program or batch file.
So its like ok just install react scripts! npm install react-scripts
I get this:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: postmassiv#0.1.0
npm ERR! Found: react#17.0.2
npm ERR! node_modules/react
npm ERR! react#"^17.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.0.0-0" from enzyme-adapter-react-16#1.15.6
npm ERR! node_modules/enzyme-adapter-react-16
npm ERR! dev enzyme-adapter-react-16#"^1.15.6" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
My error message after running npm install:
identical to above error
Note this error also occurs identically if i npm install enzyme-adapter-react-16 which I figured would be worth trying.
Tried npm install --save-dev #wojtekmaj/enzyme-adapter-react-17 but I get the same error msg. Note that this #wojtekmaj/ thing is made to replace enzyme-adapter-react-17 until its ready.
So I tried npm uninstall enzyme-adapter-react-16 and got:
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: react#17.0.2
npm ERR! node_modules/react
npm ERR! react#"^17.0.2" from the root project
npm ERR! peer react#">=16.3.2" from #restart/context#2.1.4
npm ERR! node_modules/#restart/context
npm ERR! #restart/context#"^2.1.4" from react-bootstrap#1.6.1
npm ERR! node_modules/react-bootstrap
npm ERR! react-bootstrap#"^1.6.1" from the root project
npm ERR! 9 more (prop-types-extra, react-router, react-router-dom, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^0.14 || ^15.0.0 || ^16.0.0-alpha" from airbnb-prop-types#2.16.0
npm ERR! node_modules/airbnb-prop-types
npm ERR! airbnb-prop-types#"^2.16.0" from enzyme-adapter-utils#1.13.1
npm ERR! node_modules/enzyme-adapter-utils
npm ERR! enzyme-adapter-utils#"^1.13.1" from enzyme-adapter-react-16#1.15.4
npm ERR! node_modules/enzyme-adapter-react-16
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
Here is my package.json
{
"name": "postmassiv",
"version": "0.1.0",
"private": true,
"prettier": {
"tabWidth": 4
},
"dependencies": {
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^12.0.0",
"#testing-library/user-event": "^13.2.1",
"axios": "^0.21.1",
"bootstrap": "^5.0.2",
"js-cookie": "^3.0.0",
"node-sass": "^6.0.1",
"react": "^17.0.2",
"react-bootstrap": "^1.6.1",
"react-datepicker": "^4.1.1",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"rxjs": "^7.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6"
},
"proxy": "http://127.0.0.1:8080/"
}
Found success with the npm install --legacy-peer-deps flag. It installs and runs the server. I am now doing npm audit fix --legacy-peer-deps. The server npm starts correctly.
For pattern recognition: Seems the last person I saw to have this issue also used ncu as well. Think thats how I got the issue started in the first place

after installing react-router-dom the web app shpws error in terminal on starting

I am trying to create reactjs apps and every time ,I install react-router-dom ,the web app shows error in terminal when I do npm start .
Here is the error
sh: 1: react-scripts: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! routeroute#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the routeroute#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! /home/rock/.npm/_logs/2019-03-16T10_04_47_549Z-debug.log
I tried doing rm -rf node_modules and then again installing but it doesn't seem to be working .
When I did npm install again ,
I got this error
npm ERR! path /home/rock/Desktop/routeroute/node_modules/browserslist/cli.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/rock/Desktop/routeroute/node_modules/browserslist/cli.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/rock/.npm/_logs/2019-03-16T10_19_02_250Z-debug.log
Here is the dependecies for package.json
{
"name": "routeroute",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-router-dom": "^4.4.0",
"react-scripts": "2.1.8"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
You need to update your version of npm:
Try with this command: npm i -g npm
Or you can use this: npm install npm#latest -g

Npm start error. React

I'm trying to do
npm start
In my react project but always have a problem
npm ERR! path /Users/dan/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/Users/dan/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/dan/.npm/_logs/2018-04-11T17_50_33_041Z-debug.log
I've also know that 5 version of npm isn't the best. Because I've reinstall npm and now I've:
node -v
v8.11.1
npm -v
4.6.1
package.json
{
"name": "test",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Try downgrade react-script
npm install react-scripts#2.1.8 --save
It's work for me!
Execute the following commands:
npx create-react-app myfirstreact
cd myfirstreact
npm start
It should work unless there are no files to work within the project.
Check if your react boilerplate template was fully generated by create-react-app otherwise you will need to upgrade your create-react-app
One way to know the template is not generated is if the src folder in your project directory does not exist.
your mistake is you are not in main file please run this command
cd-your file name

Resources