I everyone! I have some middleware set up in my next.js app, which I’m self hosting.
I’ve read through this guide, but it seems to have info on env vars, and info on middleware, but not info on both.
When I try to access process.env
, I see variables that are available in my deployment, but not any of the NEXT_PUBLIC
variables that I’ve set up myself.
I tried to load the env manually using this code.
import { loadEnvConfig } from '@next/env';
export function getProcess() {
const projectDir = process.cwd();
loadEnvConfig(projectDir);
return process;
}
But then I get an error in my deployment (I think at build time)
A Node.js API is used (process.cwd at line: 356) which is not supported in the Edge Runtime.
Is there any way that I can access the env variables I’ve set up?
Thank you!