Deploy next js in heroku Deploy next js in heroku heroku heroku

Deploy next js in heroku


as @monday answer very well but now heroku-postbuild script entry is no longer required because heroku now automatically running npm run build .

{  "scripts": {    "dev": "next",    "build": "next build",    "start": "next start -p $PORT"  }}


The post is six months old but hopefully, I will be able to save someone 2min of searching the internet because of this problem.your script should look like this

"scripts": { "dev": "next", "build": "next build", "start": "next start -p $PORT", "heroku-postbuild": "npm run build", "test": "echo \"Error: no test specified\" && exit 1"},

Push to GitHub

$ git init$ git add .$ git commit -m "First Commit"$ git remote add origin https://github.com/{username}/{repositoryname}$ git push origin master

Create Heroku app

$ heroku create my-app

Deploy on Heroku

  • Open your browser and sign into Heroku
  • Navigate to the “Dashboard”
  • Select your newly created app
  • Click “Deploy”
  • Under “Deployment Method” select “Github”
  • Add repository name ({username}/{repositoryname})
  • Click “Search”
  • Click “Connect”
  • Select Branch
  • Click “Deploy Branch”
  • Click “View”

you can read the entire article by Jacob Oakley


May be it is too late but like @Monday just said, you can do that and update the build command like this to avoid the sh:next command not found error

"build": "npm i && npm run build"