0

I'm trying to move all the sensitive variables to .env file. It works just fine server side on Node but I'm having trouble doing it with React.

I referenced these answers: this and that

1.I changed my .env so it looks like this

REACT_APP_SIGNER_PK = xxxxxx-xxxxx-xxxxxx

Added the variable itself to the file containing script

const REACT_APP_SIGNER_PK = process.env.REACT_APP_SIGNER_PK;
  1. Placed .env inside of my root folder
  2. I restart the server after the changes with yarn run dev

To test out the changes I put this print statement from the file where I put the env variable in

console.log(REACT_APP_SIGNER_PK);

On the restart of the local server I check the console and in the terminal where the server is running I see the print statement with my environmental variable, but in the browser console I see this print as undefined

The only thing that differs in my action from the references is that I use yarn run other than npm start

What did I do wrong?

1 Answers1

0

Thanks to the comment from @OFRBG I managed to find a solution.

Adding REACT_APP_ app to the my .env variables did not work because I was using nextJS instead of Create-React-App.

In order to fix the problem this problem for nextJS users add NEXT_PUBLIC_ instead as a prefix for your .env variables