Error encountered during NextJS build - file or directory not found for 500.html

I recently made the switch from Page Router to App router.

Transitioning

pages
  - 500.tsx

to

app
  - 500
     - page.tsx

However, I encountered an error when running yarn build/next build:

> Build error occurred
[Error: ENOENT: no such file or directory, rename '/Users/CCC/Desktop/SourceTree/my-frontend/.next/export/500.html' -> '/Users/CCC/Desktop/SourceTree/my-frontend/.next/server/pages/500.html'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/Users/CCC/Desktop/SourceTree/my-frontend/.next/export/500.html',
  dest: '/Users/CCC/Desktop/SourceTree/my-frontend/.next/server/pages/500.html'
}
error Command failed with exit code 1.

I have also reviewed next.config.js, but it doesn't seem to be the root cause of the issue

const {
  PHASE_DEVELOPMENT_SERVER,
  PHASE_PRODUCTION_BUILD,
} = require("next/constants");

const withTM = require("next-transpile-modules")([
  // '@fullcalendar/common',
  // '@fullcalendar/react',
  // '@fullcalendar/daygrid',
  // '@fullcalendar/list',
  // '@fullcalendar/timegrid',
  // '@fullcalendar/timeline'
]);

module.exports = (phase, { defaultConfig }) => {
  const isDev = phase === PHASE_DEVELOPMENT_SERVER;
  const isProd =
    phase === PHASE_PRODUCTION_BUILD && process.env.STAGING !== "1";

  const env = {...};

  const config = {
    ...defaultConfig,
    env,
    swcMinify: true,
    reactStrictMode: false,
    webpack(config) {
      config.module.rules.push({
        test: /\.svg$/,
        use: ["@svgr/webpack"],
      });
      return config;
    },
   
  };

  return withTM(config);
};

I attempted to delete the .next folder and rebuild, but the error persists. What could be causing this?

Update
I tested accessing localhost:3000/500. The UI displays correctly, however on the server side it returns GET /500 500

Answer №1

When using the app router, the ability to define custom 500 error pages is no longer available. Instead, you can create a file named: app/global-error.js.

This file will handle any errors within the App boundary that are not handled in a specific subtree.

According to the documentation:

global-error.js provides the least granular error UI and serves as a "catch-all" error handling mechanism for the entire application.

The implementation of this file could resemble the following (directly copied from the docs):

'use client'
 
export default function GlobalError({
  error,
  reset,
}: {
  error: Error & { digest?: string }
  reset: () => void
}) {
  return (
    <html>
      <body>
        <h2>Something went wrong!</h2>
        <button onClick={() => reset()}>Try again</button>
      </body>
    </html>
  )
}

Note: global-error.js is only active in production. During development, the error overlay will be displayed instead.

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

Setting time for animations in Three.js Collada format allows for precise control

Is there a way to specify time or keyframe in Collada animation keyframes? I've been attempting to do so, but I am experiencing unexpected behavior. function playAt(a){ for (var i = 0; i < kfAnimationsLength; ++i) { kfAnimations[i].p ...

How to implement a feature for uploading multiple files through a single form with unique input fields in a web

After searching on Stack Overflow, I couldn't find a suitable solution for my problem. I need help with my code that fetches data and sends it to a PHP file to upload files to specific folders and store their links in a database. However, I am encount ...

Ensure the presence of an editable column within a table using a jQuery function

Within the table, the first column is editable. Upon making a change to it, I want an alert to appear indicating that a change has occurred. The check function is being called after a delay of 5000ms. Embedding Code Snippet for Reference I suspect there ...

"Ensure that the jspdf header is configured to display on every page

Currently, I am integrating jspdf code with a jQuery script and the jspdf.debug.js file. My HTML table (angular ng-repeat) is very large and spans multiple pages. While jspdf does a great job repeating the header of the table nicely, I have some invoice in ...

Utilizing HTML5/JavaScript to send a text message from a mobile device

I am developing a mobile web application to be downloaded from various markets with a mini web server, capable of running on any operating system such as iOS, Android, Windows8, and more. My goal is to make the application as OS-independent as possible by ...

Anticipate that the function parameter will correspond to a key within an object containing variable properties

As I develop a multi-language application, my goal is to create a strict and simple typing system. The code that I am currently using is as follows: //=== Inside my Hook: ===// interface ITranslation { [key:string]:[string, string] } const useTranslato ...

ReactJS has the capability to showcase two components simultaneously

I'm facing an issue with my ReactJS workspace where I have two components but only one is displaying. import React, { Component } from 'react'; import logo, { ReactComponent } from './logo.svg'; import './App.css'; impor ...

Utilize the PHP variable HTTP_USER_AGENT to identify and analyze the user's browser

As I embark on creating a webpage, my goal is to have it display different content based on the user's browser. The SERVER [HTTP_USER_AGENT] variable initially seemed promising for this purpose, but upon inspecting the page in Chrome, I encountered: ...

Delay the rendering of the MUI DataGrid column until after the DataGrid is visible on the screen

Would it be feasible to asynchronously load a column of data in the MUI DataGrid after the table is displayed on the screen? Retrieving this additional data from the database is time-consuming, so I aim to have it appear once the table has fully loaded. T ...

Issue arising from JQuery libraries when utilizing Webpack

Having an issue with my form renderer JS script. When making an AJAX request to retrieve it, it applies functions and properties to jQuery for rendering a form. However, due to the use of webpack with another framework, there are two jQuery contexts causin ...

Locate all the small values within a given array

I am working on an application that involves gathering input from users for ten questions using select drop down boxes. The values range from 1 to 5 for each question. Upon clicking the submit button, I collect all the input values and store them in an obj ...

Performing a AJAX POST call to the latest Google Analytics V4 API

Recently, the Google Analytics v4 API was updated and now requires POST requests instead of GET requests. Unfortunately, there are not many examples available yet... I managed to obtain the accessToken, but when I attempt the following POST request, I alw ...

Issue with TypeError in Next.js 14: The error message indicates that the variable s is not recognized as a function when

Description of the issue: I have been attempting to upload an image to a Next.js serverless backend. I am using formData() to attach/set the data and then POSTing it to the backend using axios. Once on the backend, I am retrieving the formData() from NextR ...

Transforming mp4 or Avi files into m3u8 using only node js

I'm currently exploring ways to convert a mp4 or .avi file to .m3u8 using pure node js (specifically, a Firebase Cloud Function). Does anyone have any suggestions? Thank you, but I've already attempted the following: const ffmpegInstaller = requ ...

Associate an alternate attribute that is not displayed in the HTML component

Imagine there is a collection of objects like - var options = [{ id: "1", name: "option1" }, { id: "2", name: "option2" } ]; The following code snippet is used to search through the list of options and assign the selected option to anot ...

What is the reason for the multitude of json files found within the node_modules/.cache/babel-loader directory in a React application?

Recently set up a React app using create-react-app and everything seemed to be working smoothly. However, I encountered an issue while using VSCode - the git tab constantly displayed countless modifications and creations of JSON files within the folder nod ...

Exploring Next.js: Leveraging tsParticles for Dynamic Effects in Next.js

Struggling to integrate tsParticles into my Next.js project, I've been unable to locate clear documentation for its use with React or Next.js. I've scoured YouTube, Google, and every possible resource available to me in search of a solution. ...

The widths specified in the td tags do not take effect on tables with auto width

Check out this fiddle: http://jsfiddle.net/LHsLM/1/. I'm attempting to set the height and width of an auto-width table using inline CSS, as shown in the fiddle. However, the styles are not taking effect. Here's the HTML: <div id="a">< ...

"Enhancing Real-Time Communication in Angular with Websockets and $rootScope's Apply

Currently, I am experimenting with an Angular application that utilizes a websocket to interact with the backend. I've encountered some challenges in getting Angular's data binding to function correctly. In this scenario, I have developed a serv ...

Replicate the preceding input data by simply clicking a button

Here is some HTML and jQuery code that I am working with: $(".btn-copy").click(function() { var previousContent = $(this).prev()[0]; previousContent.select(); document.execCommand('copy'); }); <script src="https://cdnjs.cloudflare.com ...