1

I need to add google maps api key into my .env file.

I configured my webpack according to this config and use it in my map component. When I console log this key I can see it in console, But while using it with map, map opened just a second then I got a warning screen.

Webpack file:

plugins: [
    new Dotenv({ systemvars: true }),
],

Map component:

const { isLoaded } = useLoadScript({
    googleMapsApiKey: process.env.REACT_APP_API_KEY,  
    libraries: [GOOGLE_MAP_PLACES_LIBRARY],
});

.env file:

REACT_APP_API_KEY : "someKey"

Error that i got after a second

1 Answer 1

0

I just added this into my webpack:

const dotenv = require("dotenv").config();

For plugins:

   plugins: [
            new webpack.DefinePlugin({
                "process.env": {
                    REACT_APP_API_KEY: JSON.stringify(dotenv.parsed.REACT_APP_API_KEY),
                },
            }),]

And just used it in my component:

googleMapsApiKey: process.env.REACT_APP_API_KEY,
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.