env-cmd command is not fetching environment variables in Nextjs

141 views Asked by At

I am trying to use env-cmd to load environment variables in next js

"scripts": {
"dev": "env-cmd -f .env.build next dev -p 3006",
"build": "env-cmd -f .env.build next build",
"start": "next start -p 3006",
"lint": "next lint",
}

However, it is unable to load the environment variables in the code

const programUrl  = process.env[`PROGRAM_URL`] as string;

This line is running on the browser and the value is undefined, the .env.build has that particular environment variable.

How could this be debugged ?

0

There are 0 answers