Next.js Discord

Discord Forum

Conditional runtime export in `layout.tsx`?

Unanswered
Silver cyprinid posted this in #help-forum
Open in Discord
Silver cyprinidOP
Can I have different runtimes for production and development?

Something like
export const runtime =
  process.env.NODE_ENV !== "development" ? "edge" : "nodejs";


or equivalent.

I need nodejs runtime for some development-only features, and my app is deployed on CF pages with the edge runtime

3 Replies

Unfortunately no, that’s not possible
Why do you need to do this though? Different runtimes have different behaviours and even if it was possible to do what you are doing, there will be hidden foot guns from the differences between dev and prod
Silver cyprinidOP
I have some development only code to keep a track of project files with the fs modules and also uses child_process commands to provide access to git commands to non-developers that just use this project's UI locally. Don't need this tools for production.
So far we're git-ignoring the layout.tsx and pushing to production for deployment. Was wondering if there's a workaround