netlify/next-on-netlify sits at 727 stars on GitHub, written primarily in JavaScript. Build and deploy Next.js applications with Server-Side Rendering on Netlify!
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
We are deprecating next-on-netlify in favor of Netlify's Essential Next.js Build Plugin. Please visit this issue to learn more about the deprecation of next-on-netlify and ask any questions. You can also visit our simple Migration doc for assistance migrating to the plugin.
Build Plugin @netlify/plugin-nextjs
Plugin npm package
next-on-netlify is a utility for enabling server-side rendering in Next.js on Netlify. It wraps your application in a tiny compatibility layer, so that pages can use Netlify Functions to be server-side rendered.
Table of Contents
Installation
Setup
1. Set Next.js target to serverless
2. Add postbuild hook
3. Configure for Netlify
(Optional) Configure private git submodules
Demo
Optional Extras
Preview Locally
Custom Netlify Redirects
Custom Netlify Functions
Background Functions
Using Netlify Identity
Caveats
Fallbacks for Pages with getStaticPaths
next/image
Credits
Showcase
Installation
npm install --save next-on-netlify
Setup
1. Set Next.js target to serverless
We must build our Next.js app as a serverless app. You can read more about serverless Next.js here.
It's super simple. Just create a next.config.js file in the root of your project and write the following:
// next.config.js
module.exports = {
// Target must be serverless
target: "serverless",
};
If binaries are needed in the deployment the following configuration is needed (Prisma is an example):
// next.config.js
module.exports = {
// Target must be experimental-serverless-trace
// Your build time will be longer with this option
target: "experimental-serverless-trace",
};
2. Add postbuild hook
The next-on-netlify package adds the next-on-netlify command. When we run this command, some magic happens to prepare our Next.js app for hosting on Netlify*.
We want the next-on-netlify command to run after we build our Next.js application. So let's add a postbuild hook to our package.json file. You should add "postbuild": "next-on-netlify" to the existing scripts, like so:
*If you're curious about the "magic", check out the well-documented next-on-netlify.js file.
3. Configure for Netlify
We're almost done! We just have to tell Netlify how to build our Next.js app, where the functions folder is located, and which folder to upload to its CDN. We do that with a netlify.toml file in the root of your project and the following instructions:
Note: out_functions and out_publish are hard-coded into next-on-netlify.
These are not configurable at the moment.
(Optional) Configure private git submodules
If your project contains private submodules, in order to deploy it, you will
need to:
Generate a Deploy
Key
in Netlify and add it to the relevant
submodules
so that they can be cloned during the deploy process.
Ensure the submodule remotes are set to SSH format (i.e.
[email protected]:owner/project.git, not https://...). Inside the submodule
directory, the git remote can be updated with:
If you're not familiar with Netlify, follow the deployment instructions here: https://www.netlify.com/blog/2020/11/30/how-to-deploy-next.js-sites-to-netlify/
I recommend you still use next dev to build and preview your application locally.
But if you want to emulate the Netlify deployment on your computer, you can also run next-on-netlify locally and then use netlify-cli to preview the result.
First, install the latest version of netlify-cli (you can also look at package.json to see the version that next-on-netlify has been tested against):
npm install -g netlify-cli
Then, add the following [dev] block to your netlify.toml:
# netlify.toml
# [build]
# ...
[dev]
functions = "out_functions"
publish = "out_publish"
# We manually set the framework to static, otherwise Netlify automatically
# detects Next.js and redirects do not work.
# Read more: https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#project-detection
framework = "#static"
Lastly, add the following lines to your .gitignore:
# .gitignore
# Files generated by next-on-netlify command
/out_publish/
/out_functions/
Now you're all set.
From now on, whenever you want to preview your application locally, just run:
npx next-on-netlify watch: This will run next build to build your Next.js app and next-on-netlify to prepare your Next.js app for compatibility with Netlify. Any source code changes will trigger another build.
netlify dev: This will emulate Netlify on your computer and let you preview your app on http://localhost:8888.
Note:
Preview Mode is not yet available locally, running netlify dev, for static pages without revalidate or fallback. This will be supported soon.
For now, Preview Mode is supported in production for all Next.js page types.
Custom Netlify Redirects
You can define custom redirects in a _redirects and/or in your netlify.toml file.
The precedence of these rules are:
_redirects
next-on-netlify redirects
Currently, there is no support for redirects set in your netlify.toml file.
Read more about Netlify redirects here.
Custom Netlify Functions
next-on-netlify creates one Netlify Function for each of your
SSR pages and API endpoints. Currently, you can only create custom Netlify functions using @netlify/plugin-nextjs.
Background Functions
If your Next.js API page/route ends in -background, it will be treated as a Netlify background function.
Note: background functions are only available on certain plans.
Using Netlify Identity
You can use Netlify Identity with next-on-netlify. For all pages with server-side rendering (getInitialProps*, getServerSideProps, and API routes), you can access the clientContext object via the req parameter.
To access Netlify Identity from pages without server-side rendering, you can create a Next API route that performs identity-related logic:
export default async function getUser(req, res) {
// Get event and context from Netlify Function
const {
netlifyFunctionParams: { event, context },
} = req;
// Access Netlify identity
const { user } = context.clientContext;
// Respond with user object
res.json({ user });
}
* Note that pages using getInitialProps are only server-side rendered on initial page load and not when the user navigates client-side between pages.
Caveats
Fallbacks for Pages with getStaticPaths
Fallback pages behave differently with next-on-netlify than they do with Next.js. On Next.js, when navigating to a path that is not defined in getStaticPaths, it first displays the fallback page. Next.js then generates the HTML in the background and caches it for future requests.
With next-on-netlify, when navigating to a path that is not defined in getStaticPaths, it server-side renders the page and sends it directly to the user. The user never sees the fallback page. The page is not cached for future requests.
For more on this, see: Issue #7
next/image
Our existing solution for next/image is not very performant. We have performance improvements on our roadmap, dependent on internal work.
To get better performance now, we recommend using a cloud provider like Cloudinary (see the Next.js docs).
Credits
This package is maintained by Lindsay Levine, Finn Woelm, and Cassidy Williams.
📣 Shoutout to @mottox2 (a pioneer of hosting Next.js on Netlify) and @danielcondemarin (author of serverless-next.js for AWS). The two were big inspirations for this package.
🙌 Big "thank you" to the following people for their contributions, support, and beta testing:
@spencewood
@alxhghs
@gamliela
@wei
@laugharn
@rajington
@etrepum
@jonasbuntinx
@joostmeijles
Showcase
The following sites are built with next-on-netlify:
opinionatedreact.com (via Twitter)
missionbit.org (#18)
gemini.com
bigbinary.com
Create your own blog and deploy to Netlify!
Are you building something awesome with next-on-netlify? 🔥 Let us know and we will feature it here :)
How active is development on netlify/next-on-netlify?
The most recent commit recorded on netlify/next-on-netlify was 5.5 years ago, based on the GitHub push timestamp. The repository has 64 forks — one of the better signals of community interest.
How many stars does netlify/next-on-netlify have?
netlify/next-on-netlify has 727 GitHub stars — refresh the page for the live number, or check github.com/netlify/next-on-netlify. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What else is in the Frontend space?
netlify/next-on-netlify is tracked by TopGit under the Frontend category, alongside 8 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What language is netlify/next-on-netlify written in?
netlify/next-on-netlify is written primarily in JavaScript. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is netlify/next-on-netlify associated with?
GitHub's repository topics for netlify/next-on-netlify: "lambda-functions", "netlify", "netlify-deployment", "netlify-functions", "next-on-netlify", "nextjs", "server-side-rendering", "serverless". TopGit's editorial category is Frontend.
Where do I read more about netlify/next-on-netlify?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/netlify/next-on-netlify is the definitive source.
Why is netlify/next-on-netlify categorized under Frontend?
TopGit places netlify/next-on-netlify in the Frontend category based on its GitHub topics and description (tagged: "lambda-functions", "netlify", "netlify-deployment"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Curious whether next-on-netlify is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about next-on-netlify.