I am getting error in console "You need to enable JavaScript to run this app." reactjs

I am new to reactjs, I am working on a app. It was running fine, but when I've run npm run build command, I am getting error "You need to enable JavaScript to run this app.". I have made changes in server.js file even I've given "homepage": "./", but it did not solved my issue.

And I've checked by running laravel project, javascript is enabled in browser, also tried different browsers.

Someone please help me to overcome this error.

280596 次浏览

I had the same problem. In my case, the class name wasn't following the patterns (must starts with uppercase). As soon as I corrected it everything started to work well.

I received this message when no proxy to the server was specified inside client package.json file.

"proxy": "http://localhost:5000"

(where 5000 should be changed to whatever port number the server was setup to listen to. In my case it also required server restart once added)

I had some cookies set in the same url (localhost:8080), probably from a previous development, and it was somehow messing with my React project. I only found out because (out of despair) I tried with another browser and it worked. I deleted the cookies and it worked perfectly.

I had same problem. My workable solution:

package.json:

"homepage": "."

index.js:

app.use(express.static(__dirname)); //here is important thing - no static directory, because all static :)


app.get("/*", function(req, res) {
res.sendFile(path.join(__dirname, "index.html"));
});

Go to your SignIn component or Register component, change the form tag to a div tag OR prevent the form default i.e (e.preventDefault). Also make sure that Javascript is enabled in your browser.

Also a react newbie, I hit this issue. Remembering to add ReactDOM.render(<MyClassName />, document.getElementById("root")); fixed it for me.

I received this error because an API call that I was making was being blocked because of an invalid API key.

Try to run in other browser and see if it is working.

If it works there then please try below things and refresh your website.

  1. Right click and select Inspect.
  2. Go to Application Tab.
  3. Clear everything from local storage, session storage and cookies.
  4. Refresh your website.

This resolved similar issue in my case and hope it will work for others.

Just make sure that this route must be appeared after at all other routes

app.get("/*", function (req, res) {
res.sendFile(path.resolve(__dirname, '../client/build', 'index.html'));
})

In your react project folder install serve if you haven't installed it before;

npm install -g serve

Then serve your project with a static server;

serve -s build

The build is a folder generated by 'npm run build'.

That's it! Visit

http://localhost:5000

by default.

If you are facing the error "You need to enable JavaScript to run this app." in reactjs then 9/10 times there is an issue with your API call. Please cross check API url string, parameters, action type, endpoints, action names, controller names and API call status. You'll be able to find the issue. verify endpoint url again and again. You'll definitely find a solutions. Also check ur VPN access if you're able to hit the end point.

Go to console --> network tab and see ur API status

after adding proxy in react package.json restart the reacr server. This works for me.

Had the same issue, when I was trying serve react static files in node js server. Was missing the following in index.js of server side code.

app.use(express.static(path.resolve(__dirname, '../client/build')));

I had been struggling with this issue the whole morning and after trying all the different hacks of setting up proxy and homepage, it still did not resolve.

And then I checked my js files, and because there was an error which was not being caught while npm start, it was not enabling javascript internally.

How I got to know that this did resolve the issue: Stopping the current run and correcting the issue that was there and then rerunning the server.