Replies: 3 comments
-
There's no flag or parameter you could use, other than make sure the code is not run during pre-rendering. For example, in the with-mongo-db example, https://github.com/vercel/next.js/blob/canary/examples/with-mongodb/lib/mongodb.ts, there's this top level statement that, crashes if there's no URI for the DB present, as the builder collects information about pages. I wrote about it here, #35534 (reply in thread), but long story short, the builder "executes" the modules, and top level module code is executed as part of that.
Naturally, if you have pages that are NOT opting-out of pre-rendered Next.js will pre-render them. Things such as GetStaticProps, or when a page has no data fetching function, and no getInitialProps in _app, or in app dir, pretty much everything that's not dynamic, opts you into pre-rendering. In other words, getInitialProps in _app but not GSP, GSSP, cookies, headers functions in app dir, usage of params or search params, etc... What you can do, as shown in #35534 (reply in thread) is to switch to a getter pattern, where the checks that used to be at top of the module, live within a function instead, so that you ought to call it to trigger the code execution, and for dynamic pages that won't happen at pre-render time. I reckon also, Routes can be pre-rendered in app dir, or as they call it, if there's some given pre-conditions, then the data returned by a handler is considered to be static, and hence built at build time. |
Beta Was this translation helpful? Give feedback.
-
Hi, this is now possible, please see response here for additional info! #46544 (comment) |
Beta Was this translation helpful? Give feedback.
-
Next now has a stable API for halting prerendering here. The naming is a little awkward, "connection" doesn't exactly suggest what it does, but the idea is "this promise will resolve when a user initiates a connection" (although that's not really how promises work, like you're in two wholly different processes when building vs. at runtime, it's not the same promise that's just resolving later). Note: it doesn't stop prerendering from being attempted, but it lets you stop prerendering before any access to values that need to wait until runtime to initialize, like a database connection |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I am using server components that access Prisma in my app directory. When building my application, it looks like NextJS is running Prisma as part of its prerendering process. This causes things to break, since in my build environment, I don't have a database.
Is there a way to disable this feature?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions