Fixing Azure Static App Error while Deploying Next.js

If you encounter the following error while deploying your Next.js app to Azure Static App via a GitHub CD/CI pipeline:

You are using Node.js 16.20.2. For Next.js, Node.js version >= v18.17.0 is required.


---End of Oryx build logs---
Oryx has failed to build the solution.

Don’t worry, it’s a quick fix! You just need to add one line to your package.json file:

"engines": {
    "node": ">=18.0.0"
}

After adding this line, your package.json file should look something like this:

{
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "latest",
    "react": "18.2.0",
    "react-dom": "18.2.0",
  },
  "engines": {
    "node": ">=18.0.0"
  }
}

Happy coding 🙂