why do I get this error when building my react app? - reactjs

I keep getting this error and I'm out of ideas of what causes it:
+ npm run build:app
npm ERR! Missing script: "build:app"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
Here's my package.json if it helps:
{
"name": "environment-monitoring-app",
"version": "1.0.0-SNAPSHOT",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}

Related

Unable to start react app using npm start

I have downloaded a source code and am unable to use npm start to start the react app.
when I use npmstart I get the following errors.
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/afrasiab./.npm/_logs/2023-01-13T04_36_09_195Z-debug-0.log
following is package.json
{
"name": "react-devtools",
"version": "1.0.0",
"description": "",
"keywords": [],
"main": "src/index.js",
"dependencies": {
"react": "16.8.6",
"react-dom": "16.8.6",
"react-scripts": "3.2.0"
},
"devDependencies": {
"typescript": "3.3.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Unable to use npm start command on my react app.
Correct command for starting a react application is as :
npm run start
I think you don't install all dependencies. Agree with #Dipten
Use
npm install
I also had issue while using react first time. i have solved this issue with these lines.
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app
you can add scripts in the package.json
,"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
This error also happens if you didn't open your project from the root of the project. Make sure to cd into the folder before opening it inside VS code.
Seems like you aren't running npm start in the root directory. So first cd to the root directory and run npm start.
Also, please consider attaching a screenshot of your folder structure because it will be easy for others to help you

React js- npm install not working in a github project

I have a project from github and it has the recoil function. I'm trying npm install to run npm but it's not working:
Then I tried npm install --legacy-peer-deps, and got
61 vulnerabilities (4 low, 5 moderate, 39 high, 13 critical)
If I write npm start I got
Debugger attached.
> tgp-core-api#0.1.0 start
> PORT=3006 react-scripts start
'PORT' is not recognized as an internal or external command,
operable program or batch file.
Waiting for the debugger to disconnect...
It still says your debugger attached when you run "npm install".
Try to stop debugging (Debug > Stop Debugging or Shift+F5).
well i found out that inside my package.json i had :
"scripts": {
"start": "Port=3006 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
so i deleted Port=3006, with that i got:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
and it worked!

Port doesn't recognized while running multiple app of react on windows

I have multiple react apps example one parent app and in the parent app I have two more apps which are running on different port parent app is running on 3000 port and first child is running on 3005 and second child is running on 4000 port. I did some configurations in the package.json file in scripts section given below
parent app has
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"odmit": "npm start odmit_view",
"moderator": "npm start --prefix moderator",
"monitor": "npm start --prefix monitor",
"dev": "concurrently \"npm run odmit\" \"npm run moderator\" \"npm run monitor\""
},
first child have package.json is
"scripts": {
"start": "PORT=4000 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Second child have package.json
"scripts": {
"start": "PORT=3005 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
This will fine when I'm running this on ubuntu with command npm run dev. When I run same command in windows then it will give me the bellow error that this port is not recognized.
'PORT' is not recognized as an internal or external command,
[2] operable program or batch file.
[2] npm ERR! code ELIFECYCLE
[2] npm ERR! errno 1
[2] npm ERR! monitor#0.1.0 start: `PORT=4000 react-scripts start`
[2] npm ERR! Exit status 1
[2] npm ERR!
[2] npm ERR! Failed at the monitor#0.1.0 start script.
[2] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1]
[1] > moderator#0.1.0 start D:\odmit_view\moderator
What is the issue in this can anyone please help me.
On Windows you need to set up the environment variable first:
"scripts": {
"start": "set PORT=4000 && react-scripts start"
}
Alternatively, you can also use cross-env to work on different environments (Windows and Ubuntu) like so:
"scripts": {
"start": "cross-env PORT=4000 react-scripts start"
}

Failed to start a project with react

Starting a project with react.js, I create the project to write npm start a project I get the error, fuy to the address that says there, but I do not know how to fix it because what I ask help you the error is this: npm Err! Missing script: start. Npm Err! A complete log of this run can be found in npm Err! C:-Users-Sanvicente-Appdata-Roaming-npm-cache-_logs-2020-08-27t20_09_40_583z-debug.log. (I'm starting with react)enter image description here
If you have created react app using npx create-react-app <app_name> command then you should find a package.json file inside the <app_name> folder. Ensure that that file has the following:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}

React build with env file from a command line

Is there any way to create React App build from a command like? So far I have in the shell script:
npm install;
npm run-script build:test;
where build:test is
bash -ac '. .env.test; react-scripts build'
but that will refer to build:test script from package.json but when I want to use specific .env file in the shell script (without editing or adding anything to package.json) as follow
npm run .env.my_box react-scripts build;
that will not execute build for .env.my_box
What I have set incorrectly?
you should try this library https://github.com/toddbluhm/env-cmd
Update your package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build:stage": "env-cmd -f ./.env.stage npm run-script build"
}
then npm run build:stage
You could do something like this:
on package.json
"scripts": {
"server": "cd server && npm start",
"client": "cd client && npm start",
"server-dep": "cd server && npm install",
"client-dep": "cd client && npm install",
"install-dep": "npm install && concurrently \"npm run server-dep\" \"npm run client-dep\"",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
then npm run start for example, this is monorepo so we run server and frontend with one command

Resources