17

I tried to deploy my app to Vercel (create-react-app starter). It was deploy successful, no errors in console or my vercel account. But when i clicked a link, i have this message:

404: NOT_FOUND Code: NOT_FOUND ID: ...

How to fix that? I have React (hooks, router) and Redux store, no database, no next.js. Thank you!

Dmitriy
  • 329
  • 1
  • 2
  • 6

5 Answers5

19

I had the same problem. Turns out I had the wrong framework preset set in Vercel. Check your Build & Development Settings for your project. Be sure that 'create-react-app' is selected.

Drowned
  • 373
  • 2
  • 12
  • 1
    Thanks @Drowned ✅ ✅ ✅ – Steffi Mar 22 '22 at 18:33
  • That didn't work for me.(in vite app) In my case Clicking any link (like to "/dev") was working and even the url changes in the browser but if I write the url by myself and try to get the page it sends a 404. – Circuit Planet Sep 30 '22 at 20:10
  • 1
    @CircuitPlanet had the same problem. [This answer](https://stackoverflow.com/a/65644138/7731997) pointed me to the [`rewrites`](https://vercel.com/docs/project-configuration#project-configuration/rewrites) section for the `vercel.json` file. Adding this to the vercel config file worked for me: `{ "rewrites": [{ "source": "/(.*)", "destination": "/" }] }` – Gabriel Jablonski Nov 28 '22 at 18:43
6

i fixed this issue just now. turns out that only 1 route works, the "/" home route and other routes work for a short time, when you refresh the page, it shows a 404 page. it only happens if you don't configure your vercel.json. The routes don't get recognized except the "/" Home page route.

follow these steps:

  1. go to your project and add a vercel.json file. Then add these lines
{ "rewrites": [{ "source": "/(.*)", "destination": "/" }] }
  1. On the vercel deployment dashboard, pick vitejs as framework
  2. to learn more about this, head to their official documentation

I really hope it helps anyone on the internet

JoyShaheb
  • 129
  • 1
  • 7
4

Navigate to the build & deployment settings & check that you have selected framework if it doesn't work then add your custom commands.

enter image description here

0

for node js

   {
  "version": 2,
  "builds": [
    {
      "src": "./server.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "destination": "/"
    }
  ]
}
0

I fixed it by removing this line "baseUrl": "." in the jsconfig.json/tsconfig.json file.

user3785328
  • 674
  • 7
  • 6