-1

I am exploring this React project from the repo below and the process.env is not returning any values (undefined when I console logged them). The variables are declared in a .env.local file created at the root as per the repo's instructions and all prefixed by REACT_APP_ There is no webpack involved. It uses react-scripts to load with yarn start. Can anyone advise why it is not working?

git clone https://github.com/figment-networks/learn-solana-dapp

Thanks:)

Regina Luo
  • 1
  • 1
  • 1

1 Answers1

1

You could try without configuring dotenv first, by renaming .env.example to .env.local or any of the below link names, as I believe this was created with create-react-app(because of the presence of react-scripts)

https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used

Although it has dotenv installed, it doesn't seem to use it, to use it one would do the following:

Add this to the beginning of index.js inside src:

import path from 'path';
import dotenv from 'dotenv';
dotenv.config({ path: path.join(__dirname, '../.env.example') });

dotenv has to be configured in order to use its variables, but shouldn't be needed under create-react-app

iunfixit
  • 953
  • 3
  • 15