Replies: 5 comments 7 replies
-
Still wondering if this is an improvement or something I'm thinking about wrong. For what it's worth, I chose to wrap some of the failing code (config getting, database initialization) in a try catch to allow the build to pass, though it now spews a bunch of error logs that are safe to ignore, which is pretty terrible. Regardless, the build passes because it can now execute the code and it works in live because setting up the connection/getting configs works as intended. Pretty bad workaround for bigger projects though, since your app now doesn't follow |
Beta Was this translation helpful? Give feedback.
-
Hi @impguard. Do you have a small example of your code to make sure I'm following along? I have some code written in |
Beta Was this translation helpful? Give feedback.
-
I had a similar situation in my project. My recommendation: const database = () => connectToDatabaseOrFail(); Or use a dynamic import: export const getServerSideProps = async () => {
const database = await import('./database');
const data = await database.getData()
//...other things...
} |
Beta Was this translation helpful? Give feedback.
-
I went with a simple solution of doing this on every route that calls a database: export const dynamic = 'force-dynamic' |
Beta Was this translation helpful? Give feedback.
-
Can we please stop Next.js executing our code during build? |
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.
-
I have a page that uses
getServerSideProps
. During dev time, this works fine. I expect the code to be executed for each page request, as an SSR page should.However, during build time using
next build
, my build fails because it seems like during the "automatic optimization" stage, next decides to execute my page code. This fails due to the fact that the page automatic pulls in my database and creates a connection.This is due to the fact that my database module roughly looks like:
As a result, during build time, I fail to build my app because it cannot connect to the database. Why is this the case? I would assume by opting into server side rendering I shouldn't be executing code during build time? Is there a way to mark this as such or do I have to create workarounds of initializing my database separate from import?
Beta Was this translation helpful? Give feedback.
All reactions