In the production build of Next.js server components, fetching is not executed, unlike in development where it is carried out

SOLVED

At the beginning of my project, I was considering using internationalization for translating the pages. In the next.config.js file, there are some configurations for internationalization like the one below that caused issues:

//next.config.js
const nextConfig = {
 i18n: {
    locales: ["en-US", "tr-TR", "ru-RU"],
    defaultLocale: "tr-TR",
  },
...
}


I'm a newcomer to Next.js and have an app with App router (the one where the pages exist in the src/app folder).

When fetching all blog posts from /blog-posts and a single blog post from /blog-posts/example-name dynamic route, everything worked fine in localhost during development. However, after deploying the app on Vercel, it only fetched all blog posts on the /blog-posts page. When navigating to /blog-posts/example-name, it displayed a 404 page and showed "Failed to load resource" error in the console. The Vercel logs didn't provide any insight into the issue.

To give you more context, here is the link to the last deployment:

I followed the fetching guidelines as per Next docs: The fetch function used:

async function getData() {
  const res = await fetch("https://*backendurl*/api/getBlogPosts");

  if (!res.ok) {
    // This will activate the closest `error.js` Error Boundary
    throw new Error("Failed to fetch data");
  }

  return res.json();
}

and I called the function on the page:

const data = await getData();

Vercel deployment build logs (with { cache: 'no-store' } option):

Route (app)                                Size     First Load JS
┌ ○ /                                      0 B                0 B
├ λ /blog-yazilari                         315 B          84.1 kB
├ λ /blog-yazilari/[slug]                  536 B         84.3 kB
├ ○ /favicon.ico                           0 B                0 B
└ ○ /magaza                                135 B        77.8 kB
+ First Load JS shared by all              77.7 kB
  ├ chunks/769-f274f40a4e22dc69.js         25.2 kB
  ├ chunks/bce60fc1-5c8e6a0bf302e824.js    50.5 kB
  ├ chunks/main-app-6118df2562cf8b41.js    216 B
  └ chunks/webpack-753df88ab1dee99a.js     1.75 kB
Route (pages)                              Size     First Load JS
─ ○ /404                                   182 B        75.5 kB
+ First Load JS shared by all              75.4 kB
  ├ chunks/framework-8883d1e9be70c3da.js   45 kB
  ├ chunks/main-c4daa89c94afb7ed.js        28.4 kB
  ├ chunks/pages/_app-998b8fceeadee23e.js  195 B
  └ chunks/webpack-753df88ab1dee99a.js     1.75 kB
λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)

There are no references to the blog posts page in ISR functions:

favicon.ico
Node.js 18.x
7.5 MB
IAD1


index
Node.js 18.x
7.5 MB
IAD1


index.rsc
Node.js 18.x
7.5 MB
IAD1


magaza
Node.js 18.x
7.5 MB
IAD1


magaza.rsc

Answer №1

When using fetch, data is automatically fetched and cached indefinitely by default. To learn more, visit the documentation here.

If you need to retrieve fresh data with every fetch request, you can use the cache: 'no-store' option like this.

fetch('https://...', { cache: 'no-store' })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to showcase text formatting applied in Strapi's WYSIWYG editor in NextJS's user interface?

I'm a beginner with Next JS and Strapi CMS. Trying to figure out how to transfer styling from the backend admin panel in Strapi to the UI in NextJS. Is there a way to display the formatted text created in Strapi's WYSIWYG editor on the frontend ...

What could be causing next/image to fail in resizing images post-release only on a local server?

We've encountered a strange issue with image optimization and we're curious if anyone else has experienced something similar. Within our code base, we have implemented the following code for rendering images: imageElements: screenshotImageUrls?. ...

Steps for dynamically loading mui icons from mui with TypeScript

Is it possible to dynamically load MUI icons based on a string parameter using the following code snippet? import Icon from "@mui/icons-material" import SvgIcon from '@mui/material/SvgIcon'; const IconComponent = (props: typeof SvgIco ...

The issue persists with FastAPI CORS when trying to use wildcard in allow origins

A simplified representation of my code utilizing two different approaches. from fastapi import FastAPI middleware = [ Middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=False, allow_methods=["*"], ...

What is the process for adjusting the expiration time of a GitLab accessToken?

I am currently using NextAuth for logging in with GitLab, but I am encountering an issue where my accessToken changes every 2 hours. How can I ensure that it remains valid for a longer period so that I can successfully store it in my database? It's wo ...

Utilize React to selectively execute either Server-Side Rendering or Client-Side

My current website utilizes SSR (using nextJS) to display the landing page in the root directory. However, I am interested in having my create-react-app application displayed when a user is logged in, and revert back to showing the landing page when they a ...

Why does the error "Unable to resolve 'react-big-calendar/lib/sass/styles'" occur when using react-big-calendar with sass on Next.js?

When I tried to import 'react-big-calendar/lib/sass/styles' for my project using SASS, it resulted in an error stating: Module not found: Can't resolve 'react-big-calendar/lib/sass/styles' import { Calendar, momentLocalizer } from ...

Issue displaying getInitialProps in Next.js on the index.js file

I'm having trouble troubleshooting this code on Next.js. index.js : import { getUsers } from "../utils/users"; import React from "react"; Home.getInitialProps = async (ctx) => { let elements = []; getUsers().then((res) => { res.map(( ...

What are the steps for integrating TailwindCSS with Material UI?

I'm currently working on a project with Next.js and Material UI, but I've run into some difficulties integrating Tailwind CSS with MUI. Despite following this helpful guide, I can't seem to get the classes to apply. If anyone has any tips or ...

Encountering the following error message: "ESLint: Unable to locate module path '@vercel/analytics/react' (import/no-unresolved)", despite the package and path being existent within the file

ESLint is throwing an error message that says: ESLint: Unable to resolve path to module '@vercel/analytics/react'.(import/no-unresolved) The issue arises in this line of code: import { Analytics } from '@vercel/analytics/react'; This ...

Creating a fixed sidebar that remains visible while scrolling in Next.js

Currently, I am faced with the challenge of implementing two components - a feed and a sidebar. The sidebar contains more content than it can display at once, so I want it to be able to overflow. My goal is to have the sidebar scroll along with the content ...

The proper way to implement global scripts in Next.js

I am currently working on implementing a global fade-in animation for all components in my application. By adding the className "fadeIn" to each element and setting the default opacity to 0, I then utilize JavaScript to change it to 1 when the element is v ...

Encountering Double Axios API Calls on Page Load in Next.js 11

I've been working on migrating a React.js CRA to a Next.js SSR Application. I specifically switched to Next.js 11 because of some package dependencies that only support versions above 11. While my CRA application was running perfectly, after moving al ...

Retrieving data from the database using getStaticProps in Next.js

As I was following a tutorial on Next.js, the instructor did something that deviated from what I had learned in school and left me pondering. Here is what he did: interface FaqProps { faq: FaqModel[]; } export default function Faq({ faq }: FaqProps) { ...

Steps to transition from dynamic routing to static routing in Next.js

Is there a way to change the status of the current user using /users/[id]/activity as an example? I attempted to use http://localhost:3000/api/users/1/activity but received a 404 error page. How can I find the correct path and extract the id from the prev ...

Unique bullets for page navigation in Swiper.js/react

I've been attempting to implement custom paginations for my component in order to have bullets outside the container, but unfortunately they are not showing up in the DOM. Below is the code snippet of the component: export function CommentSlider({ co ...

When running Npm Run Dev, the website appears to be functioning properly, but unfortunately, Npm Run build

I have encountered an issue with my NextJS app where the build fails after running npm run build. The app is using stack versions of Next.js v14.1.0, npm v10.4.0, and node v21.6.2. Everything runs smoothly on localhost with npm run dev, but once I try to b ...

Exploring the Difference Between Functions in Server Actions and Server Components in NextJS

What are the benefits and distinctions between declaring an async function directly in the server component, using it inside the SC, or defining it within a server action? ...

What can be done to solve the issue with NextJS: 'next_intl__WEBPACK_IMPORTED_MODULE_1__.useFormatter) is not a function'?

While exploring the NextJS documentation, I came across the next-intl library but unfortunately, I am unable to get it to work. Upon following the guidelines provided in the official docs of next-intl, an error is encountered: Unhandled Runtime Error: E ...

I am encountering an issue with NEXTjs where SVG images are not displaying on my website

Issues with SVG Import in NextJS Website I am encountering difficulties while trying to import an SVG file into my NextJS website. I have attempted to use the <Image /> tag, as well as the <img /> and <svg> tags. While Webstorm recognize ...