Webpages appear distorted. Nextjs version 13 deployed on Digital Ocean

When I directly access the pages of my next.js website, they appear as strings of code without any errors in the Console (Chrome or Safari, with no cache). The functionality may or may not work normally when navigating from the homepage.

This is a Next.js 13 website using app router and deployed on a server (DigitalOcean).

1:HL["/_next/static/media/3876a0f72c3984e0-s.p.woff2",{"as":"font","type":"font/woff2"}]
2:HL["/_next/static/media/8a2807d88ac56020-s.p.woff2",{"as":"font","type":"font/woff2"}]
3:HL["/_next/static/media/d9b920ce8a984259-s.p.woff2",{"as":"font","type":"font/woff2"}]
4:HL["/_next/static/css/fdd13217d4859704.css",{"as":"style"}]
0:[[["",{"children":["soft-ice",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],"$L5",[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/fdd13217d4859704.css","precedence":"next"}]],["$L6",["$","meta",null,{"name":"next-size-adjust"}]]]]]
7:HL["/_next/static/css/92be51721d315283.css",{"as":"style"}]
...

See Screenshot

The errors do not occur locally in development or build/start mode.

I have noticed that only the first page accessed after building on the server works correctly. Navigating from that page to others works fine, but accessing other pages directly does not.

Any suggestions on what could be causing this issue?

I initially suspected problems with layout.tsx caused by Navbar using useRouter and usePathname. I removed them, but it did not resolve the issue. I also tried wrapping Navbar in Suspension, but the problem persists.

Answer №1

Issue Detected

The latest version of Next.js caches all requests and uses Vary headers to specify the expected results (html or rsc). Unfortunately, this Vary header is not recognized by many CDNs due to misconfigurations on their end, impacting services like Digital Ocean, Cloudflare, and others.

Resolution

To resolve this issue, I migrated from Digital Ocean to Vercel, as Vercel's platform seamlessly supports this feature given that Next.js is a product of Vercel. Since my ties with DO are not deeply rooted, this switch was feasible for me. Additionally, below are a few alternative solutions that may be worth exploring.

Alternate Fix

Suggested solution (untested): Transition from App Router configuration to Page Router in your project setup.

References

  1. Check out this GitHub thread for more insights.
  2. For updates, refer to this pull request on GitHub.

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

The assigned type does not match the type 'IntrinsicAttributes & { children?: ReactNode; }'. This property is not assignable

I have been struggling to resolve this issue, but unfortunately, I have not found a successful solution yet. The error message I am encountering is: Type '{ mailData: mailSendProps; }' is causing an issue as it is not compatible with type &apos ...

Error with Firebase authentication on a Next.js project using TypeScript

I recently started a personal project using Next.js, Typescript, and Firebase for authentication and database management. While working on a sign-in page with Google integration, I encountered an error labeled as auth/argument-error. According to the Fireb ...

Tips for including parameters in an array of values when using getStaticPaths

I'm trying to retrieve the slug value that corresponds with each number in the getStaticPaths for my page structure: /read/[slug]/[number]. The code I have is as follows: export async function getStaticPaths() { const slugs = await client.fetch( ...

Encountering a React error when attempting to generate a URL for an image in Sanity

Server Error Error: The asset reference 'e173af30-fd2d-42ed-a364-d92a2cddf32c' is malformed. It should be in the format of an id such as "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg".https://i.stack.imgur.com/koC26.png https://i.stack.imgur.com/ ...

Is it necessary to include a request in the API route handler in Next.js when passing parameters?

In my API route handler, I have a function for handling GET requests: import { NextRequest, NextResponse } from "next/server"; export async function GET(req: NextRequest, { params }: { params: { id: string } }) { const { id } = params; try { ...

NextJs is currently experiencing compatibility issues with SunEditor plugins, causing them to not

I have been encountering issues when using plugins with suneditor-react. Here is how I have imported SunEditor: import "suneditor/dist/css/suneditor.min.css"; // const SunEditor = dynamic(() => import("suneditor-react"), { ssr: fal ...

Leveraging both the value from getStaticProps and the parameter in the component within NextJS

With this code snippet, I am attempting to load markdown files from a specific directory and pass them to a component that will display one of the markdown files based on a specified parameter. However, I am encountering an error when trying to use the com ...

What steps can be taken to address the error message "FATAL: Unable to load template" encountered while using

I'm encountering the issues documented here and here on GitHub. I'm working on incorporating documentation for my Next.js code, and below is my jsdoc configuration file. { "tags": { "allowUnknownTags": true, "di ...

Decoding the HTML5 <video> tag using the html-react-parser library

I'm working on a NextJS V13 app where I need to display HTML content fetched from a CMS. Instead of using dangerouslySetHtml, I opted for the html-react-parser package to parse the HTML and replace certain embedded tags like <a>, <img>, an ...

What is the process for enabling SWC Aliased imports in Next.js?

Recently made the shift from babel to SWC. After deleting the .babelrc file, I noticed that my project no longer recognized the path aliases. In an attempt to fix this issue, I created a .swrc file. .swrc { "jsc": { "target" ...

Error 401: Unauthorized access detected while handling a Webhook

My goal is to handle a webhook sent by the authentication provider Clerk when a new user is created. To test this process locally, I initially used localtunnel without success and then switched to ngrok. Upon receiving the webhook at https://13f1-...-859 ...

I am confused about why this error is appearing so unclear: npm ERR code Unknown system error -122npm ERR

My Next.js project runs perfectly on my local machine, but when I tried to run `npm install` on cpanel, I encountered some unclear errors: npm ERR! code Unknown system error -122npm ERR! syscall writenpm ERR! errno -122npm ERR! Unknown system error -122: U ...

Error: The value of "$tweetId" cannot be parsed as it is set to "undefined". Please ensure that string values are properly enclosed

I am utilizing sanity, and if you require more details, I will furnish it promptly. When I try to access http://localhost:3000/api/getComments, I encounter the following error message: ClientError: Unable to process value of "$tweetId=undefined". Kindly ...

In Next.js 14, the cache cookie is obtained when navigating to pages, but only if there is no hard refresh

I am currently in the process of developing a small booking application using Next.js 14 without implementing any authentication. Within this app, there is a page called /events that displays a list of events, each with a "Book" button that triggers a func ...

Encountering issues with middleware functionality upon deployment on Vercel

Hey there! I have been using the headless CMS 'next-wordpress-starter' for my blog, and I recently added a middleware to manage traffic from a specific site ('x') by redirecting it back to that site. Everything was working smoothly on m ...

Is there a potential issue in Next.js 14 when utilizing the "useClient" function alongside conditional rendering in the app/layout.tsx file?

Within my app, there is a Navbar that will only be visible when the route is either "/" or "/teachers". The Navbar will not appear on the dashboard page ("/dashboard"). I achieved this using conditional rendering in the app/layout.tsx file. "use clien ...

Leveraging the power of NextJS in tandem with the versatile

Encountering challenges while attempting to merge NextJS and @emotion. In a newly created NextJS application with basic @emotion replacements, running yarn build; yarn start produces a functional but uninspiring app, although the styles are displaying cor ...

Unlocking the contents of an array from a separate file in Next.js

I am developing a Quiz App that consists of two main pages: takeQuiz.js and result.js. My goal is to transfer the data from the multiple-choice questions (mcqs) in takeQuiz.js to be accessible in result.js. Utilizing router.replace(), I ensure that once th ...

Exploring Real-Time Typescript Validation in Next.JS

Checking for TypeScript errors in Next.JS can only be done with npm run build (or yarn build). Unfortunately, running npm run dev won't display TypeScript errors, which is quite inconvenient as it would be better to have them visible in the Terminal ...

I need assistance with extracting and passing all the row and column values from a Table in React js upon clicking, in order to transfer them to another Component. Any advice or guidance on how to achieve

After creating a custom table component to display data, I need to retrieve all the row values along with their headings upon clicking and then pass them to another component. Here is the code for my table component: import PlaceBett from "./PlaceBett ...