We have an application that uses an API key (Accesstoken). We would like to hide the API key in a .env file.
We have gone through the following steps.
Created a .env file in the source folder (with the .gitignore)
Added in the .env REACT_APP_ACCESSTOKEN = pk.ffe1Ijo.......
In the terminal added the npm install dotenv
Added the into our map.component file - import dotenv from 'dotenv' dotenv.config() const accessToken = process.env.REACT_APP_ACCESSTOKEN;
Added to webpack.config.js -
externals: ["fs"], resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
Now we get the error message in the web browser console that fs is undefined. Or that the Acesstoken is not found.