Free tools Windows power users keep installed
One-click scans. No signup required.
To stop a Next.js build from querying your database, find which route function triggers the query and change when that route is generated. In the App Router, check generateStaticParams; in the Pages Router, check getStaticProps. Keep build-time queries if a public snapshot is appropriate, defer route generation when supported, or render the page at request time when data must be current or request-specific.
Find which function runs the query during the build
Start at the route that causes the query, then trace its data-fetching functions and their callers. Search the project for the database client or ORM calls, and check the build log to identify the route being generated.
- App Router: Inspect
generateStaticParamsin dynamic route segments. It runs duringnext buildbefore the corresponding pages and layouts are generated. If it queries the database to return every slug or ID, that lookup is part of the build. - Pages Router: Inspect
getStaticPropsand the paths supplied bygetStaticPaths.getStaticPropsruns at build time for pages being statically generated; Next.js permits database queries there, but that does not make them request-time queries.
The exact code change depends on your router, Next.js version, route configuration, deployment model, and whether the data needs to be fresh or personalized. There is no single safe edit that applies to every project.
Choose when the route and its data should be generated
| Approach | When the database is queried | What the page represents | When it fits |
|---|---|---|---|
| Static generation | During the build for pre-rendered pages | A reusable snapshot | Content is public, can be captured at build time, and its routes are known or enumerated then. |
| Deferred App Router route generation | When a path is first visited, in documented configurations | A generated route rather than one pre-rendered during the build | There are many possible paths or the complete route list is not needed at build time. Check the project’s configuration, especially Cache Components. |
| Request-time rendering | As the page is rendered for a request | Data selected for that request | The page needs current data or varies by request or user. |
| Static regeneration | At build time initially, then again according to revalidation behavior | A snapshot that can be refreshed | Periodic updates are adequate and a build-time query for initially pre-rendered pages is acceptable. |
These approaches trade build work against freshness and request work. Static generation produces output that can be reused; rendering at request time performs server work later to serve the request. Choose based on route count, whether paths are known at build time, how often content changes, and whether it varies by user or request.
#1 Best Overall
For App Router pages, inspect generateStaticParams
The Next.js generateStaticParams documentation describes the function as a way to statically generate dynamic routes at build time rather than on demand at request time. If your function loads every database record just to return route parameters, that enumeration can be the query you want to remove from the build.
In documented configurations, returning an empty array or using dynamic = 'force-static' can defer path generation until a path is first visited. Do not apply this pattern without checking your Next.js version and configuration: with Cache Components, an empty array causes a build error, and at least one parameter is required. Follow the guidance in the documentation for the configuration your project actually uses.
Rank #2
If paths are known and a build-time snapshot is desirable, retaining generateStaticParams may be the right choice. If the route must reflect current or request-specific data, use a request-time rendering approach compatible with your App Router setup instead of enumerating all data at build time.
For Pages Router pages, distinguish static props from request-time props
getStaticProps is a build-time data hook for statically generated pages. The Next.js Pages Router documentation allows server-side database queries inside it, but moving a query into getStaticProps does not remove that query from a build that pre-renders the page.
Recommended Free Tools
Rank #3
If each request needs to read current data, use the Pages Router’s request-time rendering option, getServerSideProps, where appropriate. The official documentation explains how request-time data fetching works. This shifts database work to page requests rather than eliminating it, so consider the server work required to serve those requests.
If periodic updates are enough, getStaticProps supports revalidation. That can refresh a static result, but it does not make the initial build-time query disappear for pages pre-rendered during the build.
Keep database access on the server
Do not move a query into browser-side JavaScript just to keep it out of next build. App Router Server Components can access a database through an ORM or database client, keeping query logic and credentials out of the client bundle. See the Next.js data-fetching documentation for server-side data access patterns.
Changing when a page is rendered does not require exposing database credentials or direct database access to users’ browsers. Keep those operations in server-side code and choose the rendering strategy that meets the page’s data needs.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallVerify the change against your project
- Identify the affected route in the build output and trace its database call to the route entry point.
- Confirm whether the route uses the App Router or Pages Router, and check its current Next.js version and rendering configuration.
- Decide whether the page can use build-time snapshot data, should generate a path on first visit, needs request-time data, or can use periodic revalidation.
- Make the matching change to the route’s generation or data-fetching strategy, preserving server-side database access.
- Run the build again and inspect its output. Then test the affected route under the project’s actual deployment configuration to confirm when the query runs and whether the page’s freshness matches your needs.
Without the project’s route code, Next.js configuration, and deployment details, the precise edit cannot be determined. The key is to remove or change the build-time caller—not to expose the query in client code.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




