Tag: Next.js

  • Configure import order in a Next.js project

    To configure import order in a Next.js project, you can use ESLint with the “sort-imports” or “import/order” rules from the “eslint-plugin-import” plugin. Here’s how you can set it up:

    Install ESLint and the necessary plugins if you haven’t already

    npm install --save-dev eslint eslint-plugin-import

    Then, create a .eslintrc.json file in your project root if it doesn’t exist already. If it does, you can just add the rules to it. In your .eslintrc.json file, you can add the “import/order” rule like so:

    {
      "plugins": ["import"],
      "rules": {
        "import/order": [
          "error",
          {
            "groups": ["builtin", "external", "internal"],
            "pathGroups": [
              {
                "pattern": "react",
                "group": "external",
                "position": "before"
              }
            ],
            "pathGroupsExcludedImportTypes": ["react"],
            "newlines-between": "always",
            "alphabetize": {
              "order": "asc",
              "caseInsensitive": true
            }
          }
        ]
      }
    }

    This will enforce a specific order to your imports:

    • Built-in modules (like fs and path)
    • External modules (like react and axios)
    • Internal modules (your own project’s modules)


    The “newlines-between”: “always” option will enforce having blank lines between each group.

    The “alphabetize” option will sort the imports alphabetically within each group.

    The “pathGroups” option allows you to customize the position of certain modules within their group. In this case, it’s making sure react always comes before other external modules.

    Then, run ESLint to check your project:

    npx eslint --fix

    This will automatically fix any issues with import order in your project according to the rules you’ve set.




    1. 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.

    2. Resolve Vercel deploy Error: Found invalid Node.js Version: “>=20.9.0”.

      If you’re deploying an application on Vercel and encounter the following error:

      Error: Found invalid Node.js Version: ">=20.9.0". Please set "engines": { "node": "18.x" } in your package.json file to use Node.js 18.

      There’s no need to downgrade your application to Node.js 18. Here’s how you can fix the issue without downgrading:

      1. Navigate to Settings.
      2. Scroll down to the Node.JS Version section. From the dropdown list, select 2.0x.
      3. Click Save.
      4. Return to the failed deployment and click on Redeploy.

      Your new deployment should successfully launch this time.