Cannot start React app due to missing script 'start' - node.js

I'm newbie to react js.Trying to run a simple app and getting this error and can't figure out what's wrong
D:\React app\react-app1>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\Muralidharan\AppData\Local\npm-cache\_logs\2022-05-29T08_51_37_315Z-debug-0.log
This is package.json file
{
"name": "react-app1",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1"
}
}
Anything wrong with installation? or outdated version something like that?

This happens becaue you have no script called "start" in your package.json file. Here is an example of a package.json file with such script:
{
"name": "your-project",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "node main.js"
},
"author": "Muralidharan",
"dependencies": {
}
}

add this to your package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
},
start is the command you need that trigger react-script to run your project
build, test and eject are other command you will need for development process

Related

Getting missing script: start error in npm

I get this error when I run npm start.
npm ERR! Missing script: "start"
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! 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\USER\AppData\Local\npm-cache\_logs\2022-04-28T13_04_19_260Z-debug.log
package.json has various sections, scripts is one of them, which allows you to write npm scripts which we can run using npm run <script-name>. The error you're getting is because your start script is missing in that section.
For a node app, your package.json file should look similar to this.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"express": "^4.17.3"
}
}
In the above code, focus on the scripts section. The following line is missing in your package.json file.
"scripts": {
"start": "node app.js",
},
Add this line and you're good to go.
Option_1: Control inside file "package.json":
"scripts": {
"start": "what command is here?",
},
Option_2: Control Terminal (folder) where you write command OR open the responding terminal for your project: right-click
on the project name -> "Open in integrated Terminal"
You have to put what command you need npm to run when you give npm start.
You have to write node index.js in scripts.start in your package.json file

missing script error during the initialization of a react app

node ./postinstall.js
react-scripts#4.0.3
react#17.0.2
react-dom#17.0.2
added 1922 packages from 732 contributors and audited 1925 packages in 1282.186s
135 packages are looking for funding
run npm fund for details
found 0 vulnerabilities
A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.
You can fix this by running npm uninstall -g create-react-app or yarn global remove create-react-app before using create-react-app again.
C:\Windows\System32\react-app> npm start
npm ERR! missing script: start
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ObiTech ict Solution\AppData\Roaming\npm-cache_logs\2021-04-05T21_07_44_609Z-debug.log
I got the error above while trying to initiate a new React App
My package.json was missing the start script
The content of the package.json file looks like:
{
"name": "reactapp",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3"
}
}

Npm start problem while installing react, and how to fix it?

After installing node and global create-react-app using 'npm install -g create-react-app' I start creating my first app using 'npx(or npm i tried both) create-react-app appname' and it was successfully created until I start the 'npm start' in 'appname' directory which gave me the following errors.
E:\Sang\React\myapp>npm start
myapp#0.1.0 start E:\Sang\React\myapp
react-scripts-start
'react-scripts-start' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myapp#0.1.0 start: react-scripts-start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myapp#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\Sang Tonsing\AppData\Roaming\npm-cache_logs\2020-09-03T12_06_34_133Z-debug.log
This is my script code inside package.json
{
"name": "myfirstreact",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3"
},
"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"
]
}
}
Kindly please help me solve my problem, I am planning to build my own website using react. Thank You so Much
"scripts":{
"start":"react-scripts-start",
"build":"react-scripts-build",
"test":"react-scripts-test",
"eject":"react-scripts-eject",
}
you have to go to your package.json file and look inside scripts,
you should see there start script. if you dont have just add it.
In your package.json file change the start script as:
"scripts": {
"start": "react-scripts start -o",
"build": "react-scripts build",
.
.
.
I think it's "start": "react-scripts-start" which is causing problem for you.
You may be missing the react-scripts module.
Run npm install react-scripts --save in your project and your package.json should be the way it was initially:
"scripts":{
"start":"react-scripts start",
"build":"react-scripts build",
"test":"react-scripts test",
"eject":"react-scripts eject",
}
nvm install 10.23.0
npm start
npm run build
Brother I think your npm version or nodejs version is outdated
You’ll need to have Nodejs >= 14.0.0 and npm >= 5.6 on your machine. Or use windows 8.1 , 10 . Not the windows 7
Simple delete the node_modules folder and run npm install in the appname directory. Let me know if it don't help.
delete node_modules
run npm install
after that run npm start
if above does't work
delete node_modules
delete package-lock.json
run npm install
and then npm start
if above solutions does not fixed your problem, try the following this worked for me:
if you want to start on another port or PORT command not found error then do the following steps:
open package.json file
inside script replace the start command with below "start": "set PORT=3006 && react-scripts start"

Node.js.json failure

I am getting an error for the following package.json file.
If you already have a default version of it. I would be appreciated.
Thanks.
D:\Dev\survey-reactjs>npm run start
npm ERR! code EJSONPARSE
npm ERR! file D:\Dev\survey-reactjs\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 288 while parsing '{
npm ERR! JSON.parse "name": "survey-reactjs",
npm ERR! JSON.parse "version'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Asus\AppData\Roaming\npm-cache\_logs\2020-07-16T23_48_39_175Z-debug.log
The updated version is below:
Edit:
D:\Dev\survey-reactjs>npm run start
> survey-reactjs#0.1.0 start D:\Dev\survey-reactjs
> node server.js
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'D:\Dev\survey-reactjs\server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! survey-reactjs#0.1.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the survey-reactjs#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\Asus\AppData\Roaming\npm-cache\_logs\2020-07-17T00_26_04_833Z-debug.log
Package.json file
{
"name": "survey-reactjs",
"version": "0.0.2",
"description": "",
"main": "''",
"scripts": {
"build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
"dev": "webpack-dev-server --progress --profile --colors --hot"
"start": "node ./scripts/start.js",
},
"dependencies": {
"json-loader": "^0.5.4",
"json5-loader": "^0.6.0",
"jsx-loader": "^0.13.2",
"node-libs-browser": "1.0.0",
"react": "15.0.1",
"react-dom": "15.0.1"
}
}
The updated version is below.
Edit :
{
"name": "survey-reactjs",
"scripts": {
"start": "node server.js"
},
"version": "0.1.0",
"private": true,
"dependencies": {
"cra-template": "1.0.3",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-scripts": "3.4.1"
}
}
I have installed over the scratch but gets different error this time.
This JSON contains two errors:
{
"name": "survey-reactjs",
"version": "0.0.2",
"description": "",
"main": "''",
"scripts": {
"build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
"dev": "webpack-dev-server --progress --profile --colors --hot"
"start": "node ./scripts/start.js",
},
"dependencies": {
"json-loader": "^0.5.4",
"json5-loader": "^0.6.0",
"jsx-loader": "^0.13.2",
"node-libs-browser": "1.0.0",
"react": "15.0.1",
"react-dom": "15.0.1"
}
}
It has a missing comma in one place and an extra comma in another place. It should be this:
{
"name": "survey-reactjs",
"version": "0.0.2",
"description": "",
"main": "''",
"scripts": {
"build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
"dev": "webpack-dev-server --progress --profile --colors --hot",
"start": "node ./scripts/start.js"
},
"dependencies": {
"json-loader": "^0.5.4",
"json5-loader": "^0.6.0",
"jsx-loader": "^0.13.2",
"node-libs-browser": "1.0.0",
"react": "15.0.1",
"react-dom": "15.0.1"
}
}
A comma was added at the end of the "dev" line and a comma was removed after the "start" line. In the future, you can check your own JSON here: https://jsonlint.com/
This is probably not error with your package.json, If it was no error with your package.json then on npm run start you would not be getting error of module not found, So the error is module not found ! now, which module?
Please look closely at the issue D:\Dev\survey-reactjs\server.js
Please check the following:
Do you have server.js file on the above path directory, if it is there then please do check if you have any package you have used but never installed it through npm install package name
2.if above solution do not give you good result I suggest you try building project from below steps:
Whenever starting a project :
Build your package.json from npm init
then start installing packages required through npm install
then put you server.js file at root directory only
Please note that: Nodejs considers all your installed packages and any of JS file that you write as a seprate module

sh: react-scripts-start: command not found

I have a project that I cannot run npm start on.
I haven't touched this project in two weeks. The only thing I did yesterday was add a git repository, that's it.
When I tried to run npm start I got this error:
sh: react-scripts-start: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! bk-react-replica#0.1.0 start: 'react-scripts-start'
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the bk-react-replica#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I've looked at the solutions on other posts about this same error but none work for me. I've deleted the node_modules directory and package-lock.json files, then ran npm install.
However, I still get the same error message. Does anyone know what's wrong?
This is my package.json file:
{
"name": "bk-react-replica",
"version": "0.1.0",
"private": true,
"homepage": "http://qhafeezdomain.dreamhosters.com/projects/bkreplica",
"dependencies": {
"antd": "^3.3.0",
"normalize.css": "^8.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-native-scripts": "^1.13.1",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"react-scripts": "^1.1.4",
"react-scripts-cssmodules": "^1.0.171",
"redux": "^3.7.2"
},
"scripts": {
"start": "react-scripts-start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
As I will reference you to an answer I provided to a question similar to yours, run this:
npm i -g npm //which will update npm
rm -rf node_modules/ && npm cache clean // to remove the existing modules and clean the cache.
npm install //to re-install the project dependencies.
Edited:
I just noticed your package.json it should be:
"scripts": {
"start": "react-scripts start",
not
"scripts": {
"start": "react-scripts-start",

Resources