Environment variables not working (Next.JS 9.4.4)

if you are using latest version of nextJs ( above 9 )

then follow these steps :

  1. Create a .env.local file in the root of the project.
  1. Add the prefix NEXT_PUBLIC_ to all of your environment variables.
eg: NEXT_PUBLIC_SOMETHING=12345
  1. use them in any JS file like with prefix process.env
eg: process.env.NEXT_PUBLIC_SOMETHING

Leave a Comment