Solving the “/app/.next/standalone not found” Error in Next.js

While building your Nextjs application within Docker, you may encounter the following error if you’re using the Docker sample from the official Nextjs GitHub site:

"ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 83cmddfvrmzj1u5evc3q6uxwx::7xxwejdn2kuni31k09czx9kpk: "/app/.next/standalone": not found"

This blog post offers a straightforward solution to this problem.

Understanding the Error

Understanding the Error

The error message suggests that the system couldn’t compute the cache key as it was unable to calculate the checksum of a specific reference, “/app/.next/standalone”, which it couldn’t find. This error typically arises when Next.js attempts to build your application but can’t locate the specified reference.

The Solution

The solution to this error is quite simple. You just need to add a line in your next.config.js file:

output: 'standalone',

This code instructs Next.js to output your application as a standalone app, meaning your application will contain all the necessary files and configuration settings to run independently, without relying on external resources.

Here’s how to do it:

  1. Open your next.config.js file, which is usually located at the root of your project directory.
  2. Add the line output: ‘standalone’, to the configuration object. Ensure that you add this line within the module.exports object.
  3. Save the changes and close the file.
  4. Rebuild your Next.js application.

Your next.config.js file should look like this after adding the line:

const nextConfig = {
  // ...other configuration settings...
  output: 'standalone',
  // ...other configuration settings...
}

After following these steps, the error should no longer appear when you build your application. Your Next.js app should now build successfully and run as a standalone application.