.env file in the project root:
ESRI_KEY=api_key_value
For the webpack config I have:
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
module.exports = {
//----//
plugins: [
new Dotenv(),
],
};
and the code is:
console.log(process.env.ESRI_KEY);
const ESRI_KEY = process.env.ESRI_KEY;
const geocodeService = L.esri.Geocoding.geocodeService({
apikey: `{ESRI_KEY}`,
});
I tried different combinations of passing like
apikey: `${ESRI_KEY}`
apikey: ESRI_KEY
and all of them work. I actually can see the ESRI_KEY value in the console and I can see it in the dist folder ether hidden on visible (depends on passing syntax). There are no errors in the console but for some reason, nothing happens unless I pass direct value like:
const geocodeService = L.esri.Geocoding.geocodeService({
apikey: 'api_key_value',
});
There simply should appear a popup with the address of the place on the click (and it works if a pass direct api_key_value or simply use another js file with the value and place it on top of my main js in the HTML) but it doesn't work with .env and I can't figure at why and how to fix it.
In python, I had only one issue like this with a database password. Regardless of the rest of the environment variables Postgresql accepted only direct password_value in my main.py. So I'm trying to understand if my issue is related to code/webpack/.env or some keys specific.