Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NextJS deployed to Vercel: 404 page not found

Tags:

next.js

vercel

I have a NextJS app without an integrated api that I want to deploy to Vercel. It works fine when I run it locally yarn run dev and I can also build it yarn run build without any errors. When I deploy it Vercel, however, I receive a 404 Error.

Here is my folder structure:

app/
  - components
  - pages
    - editor
      - [id].tsx
    ...tsx
  - public
  - utils
    - db
      api.ts

I am using NextJs 10.0.3.

Here is a link to the deployed app.

I don't have a nextjs config file. My assumption is that the error is caused by the dynamic route but I can't find my mistake. Also, no page is working when the app is deployed as opposed to only the dynamic page.

Do you have pointers on where to look next?

EDIT 1:
Here is a link to the GitHub repo.

EDIT 2: I found an issue but don't know how to fix it.

This is how my build output looks like on Vercel: enter image description here

This is how it's supposed to look like on Vercel: enter image description here

Not sure why the whole _next folder is missing.

like image 350
siva Avatar asked Jan 18 '21 08:01

siva


People also ask

Why do I see a 404 error when accessing my deployment vercel?

And the 404 error is returned by Vercel because they don't recognize that subdomain.

How do you force deploy in vercel?

Vercel CLI automatically detects the framework your project is using. After the initial step, you can run the vercel command again to create a Preview Deployment. To create a Production Deployment, use the vercel --prod command. Making a Production Deployment with the vercel command.

What is nextvercel?

Vercel enables you to develop, preview, and ship every Next.js feature, without configuration. Developed by the team behind Next.js, Vercel will automatically support every Next.js feature, forever. Vercel takes the zero-configuration mentality of Next.js to the cloud, so you can deploy your app in seconds.

How does Vercel work with next JS?

The deep integration between Next.js and Vercel’s Edge Network allows you to preview, test, and deploy your app without worrying about infrastructure. Performance optimizations built into Next.js are automatically supported and enhanced on Vercel, creating smooth, interactive experiences that feel instant for every user.

Can I use next JS on Netlify to generate 404 errors?

For other errors, you can do the exact same thing with an _error.js file in the pages/ directory! The 404 error is special because it is always statically generated, but the others rely on the server. If you'd like to use the server-rendering aspects of Next.js on Netlify, check out our one-click install build plugin.

Does nextjs work on the local machine?

On development mode (local machine) everything works fine. Both static and dynamic routes are working properly and fetching data from the dontnet core Web API. However, when publishing the Nextjs app following this steps:


Video Answer


4 Answers

I just had this exact same issue. I have my Next app in a sub directory. I think that might be the cause of some problems.

What worked for me was.

  • Make sure to pick the right sub directory. Mine had a little Next Js icon on it.
  • The framework preset needs to be set to Next.js.
like image 51
CarlThePerson Avatar answered Oct 17 '22 15:10

CarlThePerson


Edited

Try to deploy using now --prod --force The --force flag will clear your build cache (in production) and force production push. If still no working then make sure to add now.json

like image 25
Mohit Chandel Avatar answered Oct 17 '22 15:10

Mohit Chandel


Go to Project Settings

Change Framework preset from Other to Next.js

Redeploy the project.

like image 9
Anirudh Avatar answered Oct 17 '22 15:10

Anirudh


Also make sure to choose Next.js as Framework preset (and not other). You can find that in Project settings and under Build & Development Settings. More here: https://vercel.com/docs/concepts/deployments/build-step

like image 2
Haris Khan Avatar answered Oct 17 '22 16:10

Haris Khan