React shows 'You need to enable JavaScript to run this app' with JavaScript on
You need to enable JavaScript to run this app.Short answer
Seeing that sentence with JavaScript on means the HTML page loaded but your app did not start, or an API call got the HTML page back. Check which request returned index.html. The usual causes are asset paths that do not match where the build is hosted, and a server catch-all route that answers requests it should not.
Fix it fast
1Find out which cause you have
Request the JavaScript file and the API route directly. If either one returns the HTML page, that response is the problem.
curl -s http://localhost:3000/ | grep -o 'src="[^"]*"' curl -s -i http://localhost:3000/api/items | head -n 82Match what you see, then jump to its fix
- 1
The page is blank with the message, and the script request in the network tab returns index.html or 404The build assets load from the wrong base pathFix - 2
fetch('/api/...') returns the HTML of index.html; the response body starts with <!DOCTYPE html>A catch-all route answers requests meant for files or the APIFix - 3
Works in production, but with npm start the fetch gets the app's HTMLIn development the request is not forwarded to the API serverFix
- 1
What does the error look like?
You need to enable JavaScript to run this app.fetch('/api/...') returns HTML instead of JSON
Cause 1 of 3
The build assets load from the wrong base path
1Check
A build assumes it is served from the server root unless package.json has a homepage field. Open the built index.html and look at the script and stylesheet URLs.
grep -o 'src="[^"]*"' build/index.html2Fix
Set homepage to where the app is hosted. A relative value of . makes asset paths relative when you do not use client-side routing. Rebuild afterwards.
// package.json
"homepage": "."
npm run build3Verify
Serve the build and load a page; the scripts now return JavaScript, not HTML.
npm install -g serve
serve -s build
curl -sI http://localhost:3000/ | head -n 1Confirmed by create-react-app.dev
Cause 2 of 3
A catch-all route answers requests meant for files or the API
1Check
In Express, a wildcard that sends index.html catches every path that no earlier route handled. Routes registered after it never run.
curl -s -i http://localhost:5000/api/items | head -n 122Fix
Register static files and API routes first, and put the index.html catch-all last.
app.use(express.static(path.join(__dirname, 'build')));
app.use('/api', apiRouter);
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});3Verify
The API URL now returns JSON and the browser URL for a client route returns the app.
curl -s -i http://localhost:5000/api/items | head -n 12Confirmed by create-react-app.dev
Cause 3 of 3
In development the request is not forwarded to the API server
1Check
The development server forwards only requests without text/html in their Accept header to the proxy target, and only when proxy is set. Check package.json.
grep -n '"proxy"' package.json2Fix
Set proxy to your API server, restart npm start, and call the API with fetch so the Accept header is not text/html.
// package.json
"proxy": "http://localhost:4000"3Verify
The request in the network tab reaches the API and returns JSON.
npm startConfirmed by create-react-app.dev
How do I stop it coming back?
- Keep static and API routes ahead of the index.html catch-all in every server.
- Test the production build with a static server before deploying, not only npm start.
- Use full or env-driven API base URLs so a wrong path fails with a clear 404.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
Related fixes
Back end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
The AWS SDK in Node.js cannot find any credentials
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
The AWS SDK walks a fixed credential chain: code, environment variables, the shared files in ~/.aws, then role sources such as ECS or EC2.
3 causes, each with a fixBack end
AWS SDK for JavaScript v3 cannot find credentials, even for DynamoDB Local
A DynamoDB client pointed at http://localhost:8000 fails with the same message
The SDK walked its default credential provider chain and found nothing.
3 causes, each with a fixBack end
AWS SDK says the security token included in the request is invalid
The security token included in the request is invalid
The call reached AWS but the credentials it carried were refused.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fix