Variables Declared in .env file in ReactJS, NextJS app are coming as Undefined

Viewed 3363

This is what I have in my .env.local file:

REACT_APP_API_PATH=http://localhost:3600/

.env.local file is at the root level.

This is how I am trying to use this variable:

console.log('node env' + process.env.NODE_ENV)
console.log('api path : ' + process.env.REACT_APP_API_PATH)
fetch(process.env.REACT_APP_API_PATH + 'auth', requestOptions)

Console.log 'node env' is printing development. Console.log 'api path' is printing undefined. I am using ReactJS with NextJS. I start my server with 'yarn dev' command. I have stopped and started the app multiple times.

1 Answers

Finally, had to upgrade my NextJS version to 9.4 from 9.3.5 and it started working.

Related