js-api-loader icon indicating copy to clipboard operation
js-api-loader copied to clipboard

Failed to resolve module specifier "@googlemaps/js-api-loader" for Google Maps node express server

Open kyle4346 opened this issue 3 years ago • 0 comments

I'm using the google Maps javascript api and importing the module is giving an error:

Failed to resolve module specifier "@googlemaps/js-api-loader"

Here is my javascript code:

import { Loader } from "@googlemaps/js-api-loader";


const { config } = require('dotenv');
config();


const loader = new Loader({
  // Put javascript maps API key here
  apiKey: process.env.API_KEY,
  version: "weekly",
});

loader.load().then(() => {
  map = new google.maps.Map(document.getElementById("map"), {
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8,
  });
});

Finally, here is my html code

<!DOCTYPE html>

<html lang="en">


  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>New App</title>
    <meta name="description" content="Google Maps Deal Finder" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- css styling -->
    <link rel="stylesheet" href="styles/styles.css" type="text/css" />
    <!-- css styling -->
    <!-- Map Data-->
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <script
      type="module"
      src="javascript/index.js"
      type="application/javascript"
    ></script>
<!-- Map Data -->
  </head>
  <body>
    <div id="map"></div>
  </body>
</html>

Screenshot 2022-11-07 014746

kyle4346 avatar Nov 07 '22 07:11 kyle4346