Npm start won't start React App and no error - reactjs

I created a new React App and npm start was working in localhost. After I closed it and went back later npm start will not open in the browser. I reinstalled everything and the exact same thing happened again. I tried installing react-scripts globally. Nope. Same thing. I deleted node_modules and still nothing. I tried removing babel from my package.json. Nothing. I cleared my cache from the browser. Nothing. Any help would be great. I have made many React Apps and never had anything like this.
Here is my package.json:
{
"name": "johnny_auth1_app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"bootstrap": "^4.5.3",
"react": "^17.0.1",
"react-bootstrap": "^1.4.0",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.1",
"styled-components": "^5.2.1",
"web-vitals": "^0.2.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"
]
}
}
Here is my App.js:
import './App.css';
import Home from './Components/Home';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { NavigationBar } from './Components/NavigationBar';
const App = () => {
return (
<Router>
<NavigationBar />
<div classname='App'>
<Switch>
<Route exact path='/' component={Home}/>
</Switch>
</div>
</Router>
);
};```

This issue may be from the browser you are using. Copy the local host address and past it on different browsers. You may also need to restart your PC if you recently did some installations on the PC.

Related

React js application isn't running on localhost:3000

I have tried many many times but my http://localhost:3000 not working at all.
Just taking reload & reload
Console log is also clear. nothing at there.
1st time when I faced this problem, I cleared the history, then it works but now this is not working,
After giving so much pressure, it shows me,"
Aw, Snap!
something went wrong while displaying this webpage.
"
my app.js file:
import './App.css';
function App() {
return (
<div className="App">
<h1>Hello World</h1>
</div>
);
}
export default App;
my package.json file:
{
"name": "secret-name",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.1.1",
"#testing-library/user-event": "^13.5.0",
"bootstrap": "^5.1.3",
"react": "^18.1.0",
"react-bootstrap": "^2.3.1",
"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"
]
}
}
Just the title of my website appears at the top.
I can't create a new react app because this is an assignment and I have pushed the primary code to the private repository. I don't want more problems.
After facing this problem, I deleted the package.lock.json & node_modules and then again install the packages by npm install.
What can I do now?
I think that something went wrong when you create the project.
Try to create a new one
npx create-react-app my_app_name
And the run
npm run start

Adding Chakra UI after starting development of Create React App

I'm getting an error after I tried adding ChakraUI to my create-react-app. Hoping for any help (also suggestions for what to add to a stackoverflow question is also appreciated)
I ran yarn add #chakra-ui/react #emotion/react#^11 #emotion/styled#^11 framer-motion#^4 as suggested in https://chakra-ui.com/docs/getting-started
I used CRA to start my app but decided to add chakra after I already started a bit of development. That's why I didn't use yarn create react-app my-app --template #chakra-ui
However after running yarn & yarn start I get this error about framer-motion:
TypeError: framer_motion__WEBPACK_IMPORTED_MODULE_1__.motion.custom is not a function
my index.js file looks like this:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { ChakraProvider } from '#chakra-ui/react';
ReactDOM.render(
<React.StrictMode>
<ChakraProvider>
<App />
</ChakraProvider>
</React.StrictMode>,
document.getElementById('root')
);
package.json:
{
"name": "gad-questionaire",
"version": "0.1.0",
"private": true,
"dependencies": {
"#chakra-ui/react": "^1.3.4",
"#emotion/react": "^11",
"#emotion/styled": "^11",
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"framer-motion": "^4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"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"
]
}
}
Using react version: 17.0.1
npm i framer-motion#3.10.6
👆 worked for me, 4.0 appears to have breaking changes

How to fix a 404 on react app deployed on github pages?

I have tried to deploy my react app on github pages, but am getting a 404 error. However the site is able to access my app as the 404 page is my custom one. I followed the deployment steps from https://github.com/gitname/react-gh-pages.The github page is https://ritsar.github.io/LapStore/ and the respective remote repository is at https://github.com/RitSar/LapStore. I get no errors on the terminal when i run npm run deploy.I am trying to make ritsar.github.io/LapStore my root, i.e to access index.html. On navigating within the site from the navbar, home page is directed to ritsar.github.io/,where images are not accessible and cart is directed to /cart instead of /LapStore/cart.
package.json
{
"homepage": "http://RitSar.github.io/LapStore",
"name": "e-commerce",
"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",
"bootstrap": "^4.5.2",
"jquery": "^3.5.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-owl-carousel": "^2.3.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^3.4.3",
"serialize-javascript": "^4.0.0",
"styled-components": "^5.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"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": {
"gh-pages": "^3.1.0"
}
}
I have tried changing "homepage" to "http://RitSar.github.io", ".", "http://RitSar.github.io/LapStore/index.html", made minor changes to index.html and redeployed, changed branch folder on github settings to /docs from /(root) as per relative suggestions from other threads.
Same app hosted on heroku is at https://lapstore-ritsar.herokuapp.com/. (Page loading slowly despite of images having size less than 50kb is an issue for another time, I would like to know how to correctly deploy the same on github pages).
Your main page with router <Route exact path="/" component={ProductList}></Route>. With exact path, it will not work on gh-page and you need to add 1 more route /LapStore.
Try to remove exact the route and add new route:
<Route path="/" component={ProductList}></Route>
<Route path="/LapStore" component={ProductList}></Route>

React default create-react-app App component rendered twice

I started new React project via the command:
npx create-react-app my-app --template typescript
Then, I changed the App component to look like that:
import * as React from 'react';
export default class App extends React.Component<{}> {
public render() {
console.log("App Rendered");
return (
<div>
Hello World
</div>
);
}
}
and when I watch the Console log ( both in Google Chrome and Microsoft Edge ) I receive this messages:
[HMR] Waiting for update signal from WDS...
App Rendered
App Rendered
My Questions:
Why the App render is being called twice?
How to remove the first message with that WDS?
This is my package.json ( default one as I ran create-react-app ):
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"#types/jest": "^24.0.0",
"#types/node": "^12.0.0",
"#types/react": "^16.9.0",
"#types/react-dom": "^16.9.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"typescript": "~3.7.2"
},
"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"
]
}
}
When wrapped with React.StrictMode (which is how CRA template are setup), on development, renders will be called twice. This is done to catch bugs that might occurs when some setState functions are not pure. You can read this for more detail.
Remove React.StrictMode from src/index.tsx

I get a blank page after deployment to github without any error

I built something from react for the first time, and I'm about to deploy it on my github.
But when I go to my repository from github, it displays a blank page(But I'm not sure if the part of css is working as I can see black background color on it)
Since it doesn't show any error on the console, it was hard for me to figure out what the problem is.
I'd be great if someone can help me out on this.
https://stone-skipper.github.io/svs/#/
This is the link I'm trying to deploy on.
- Some people mentioned the problems from BrowserRouter, so I tried HashRouter, but it also didn't work.
// App.js
import React from "react"
import { Sev, Contents } from "./screens"
import { BrowserRouter as Router, Route } from "react-router-dom"
import "./App.css"
function App() {
return (
<Router>
<Route exact path="/" component={Sev} />
<Route path="/contents" component={Contents} />
</Router>
)
}
export default App
//package.json
{
"homepage": "http://stone-skipper.github.io/svs/",
"name": "sev-exhib",
"version": "0.1.0",
"private": true,
"dependencies": {
"modali": "^1.2.0",
"react": "^16.8.6",
"react-cursor-position": "^3.0.3",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"styled-components": "^4.3.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"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": {
"gh-pages": "^2.1.1"
}
}
//index.js
import React from "react"
import ReactDOM from "react-dom"
import "./index.css"
import App from "./App"
import * as serviceWorker from "./serviceWorker"
ReactDOM.render(<App />, document.getElementById("root"))
serviceWorker.unregister()

Resources