How to successfully load the google-map-react library

After installing the google-map-react library locally in my app, I verified that it is listed in my package.json under dependencies. The corresponding folder also exists in the node_modules directory. However, when attempting to reference the component constructor in a file with this line of code:

import GoogleMapReact from "google-map-react";

I encountered errors upon running the code:

Error: Cannot find module 'google-map-react'

./src/components/partials/Test.jsx
Module not found: Can't resolve 'google-map-react' in '/usr/local/bab/src/components/partials'

The path referenced in the second error appears to be incorrect as it mentions /usr/local while my app is located at ~/www/...

I am uncertain about what I may have done incorrectly. Note that the library has not been installed globally and I even attempted removing it using

npm uninstall -g google-map-react
, but did not see any improvement.

System: Ubuntu 18.04
Node: v10.15.3
NPM: 6.4.1

Here is a snippet from my package.json file:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/polyfill": "^7.2.5",
    "@babel/runtime": "^7.2.0",
    "axios": "^0.18.0",
    "google-map-react": "^1.1.4",
    "moment": "^2.23.0",
    "node-sass": "^4.11.0",
    "prop-types": "^15.6.2",
    ...
  },
  "scripts": {
    ...
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    ...
  }
}

Answer №1

To resolve the issue, first delete the google-map-react folder from your node_modules directory and then remove it from the package.json file. After that, run the following command: npm install --save google-map-react. Finally, verify if the google-map-react folder is present inside the node_modules directory.

Answer №2

Attempt removing all the node modules and then re-install by following these steps:

rm -rf node_modules
npm install

It is possible that there might be a problem with conflicting node modules.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The implementation of SetInterval within nested functions in JavaScript appears to be malfunctioning

I am a beginner in the world of JavaScript and I am currently attempting to incorporate the setInterval method within functions in Js. JavaScript Code: var tar = document.getElementById("sample"); function dataSample(tar) { //setInterval ...

How can you pick the element that is nearest to the top of a window?

My goal is to have a fixed list of page sections on the side that highlights the link of the section you're currently viewing as you scroll through the page. This is the code I've come up with: $(document).scroll(function(){ $allSections = $(&a ...

Adjusting height in Google Maps to fill the remaining space

Currently, I am developing a map application where I want the Google Maps DIV to occupy the remaining height under the header. Here is the code snippet: <!DOCTYPE html> <head> <title>Map Application</title> <style type ...

Guide to activating the timer specifically on select pages with jQuery Mobile

I've developed a quiz application using jQuery Mobile and I am working on implementing a timer feature. The timer should run from 0 seconds up to 1 hour but only when the user is viewing specific pages, specifically the question pages. The timer is di ...

Ways to retrieve a grandchild element of a specific element using its tag name

I'm struggling to access elements that are nested within various levels of parent elements with and without IDs. The usual method getElementByTagName doesn't seem to be working for me, especially when the target element is three levels deep. Is t ...

Facing an issue where WordPress AJAX is not showing the expected content

Currently, I am in the process of creating a WordPress website that will feature an initial display of two rows of images. Upon clicking a button, two more rows should dynamically appear. There are four key files involved in this project: case-study-ca ...

Executing npm build on a Python app in Heroku: A step-by-step guide for deployment

My web application is built using a Python/Django backend API and a Vue.js frontend. We serve the static files produced by Vue as static Django files, with the frontend application located in a separate folder within the Django project. Prior to each depl ...

Converting HTML to a Text String (not for display) using Angular

When it comes to displaying HTML in Angular, there are numerous approaches available. For example, using $sce.trustAsHtml(myHtmlVariable) is one way to achieve this. However, I am interested in creating something like the following: myStringVariable = s ...

Showing a pop-up dialog box once a value has been selected

When the ajax autocomplete value is selected in a certain textfield, I want to display a message box. To achieve this, I am utilizing the jquery-confirm JavaScript library which can be found here. Below is my code snippet: select: function( event, ui ) { ...

Having trouble setting headers in my React API due to them already being sent

I am encountering an error when calling my API that states 'Can\'t set headers after they are sent.. Can someone please assist me in understanding why I am receiving this error? Below is the complete code of the API, can anyone take a look a ...

Modifying various items depending on the variable's value

I'm attempting to adjust various variables depending on which button the user clicks. For instance, there are three buttons: <button id="button1" onclick="isClicked(this.id)">B1</button> <button id="button2" onclick="isClicked(this.id) ...

Is there a way to pass a token variable from the main page to an iframe without relying on a post message?

I am seeking assistance on how to transfer a variable from a parent window to an iframe. My situation is as follows: I am working with 2 Angular5 applications named A and B . Application B is loaded within Application A using an iframe. The aut ...

Overlapping Dropdown Javascript Menus

To achieve the desired effect in the header, I need to create two expandable dropdown menus for the first two titles. My coding experience is limited, especially when it comes to javascript and jquery. Currently, I have managed to create the effect for one ...

What causes the variance in the node_modules directory between a project being installed locally versus globally?

Imagine I have a project called X, which depends on another package, Y. Y in turn has its own dependency on Z. When I run npm install Y in my project, the structure of my node_modules folder is as follows. Take note that Z is installed as a direct depend ...

The error message "npm start error - No production canister_ids.json can be located. Proceeding with local

Every time I execute npm start, the same "error" message pops up saying "No production canister_ids.json found. Continuing with local" Initially, there appeared to be a proxy issue that was visible in the browser console. I was able to resolve it by makin ...

Connecting to a MongoDB or Mongoose database dynamically using Node.js

I am currently working on developing a multi-tenant application where each client will have its own dedicated database. Here is my scenario: I have created a middleware that identifies the client based on their subdomain and retrieves the necessary datab ...

Leveraging jQuery.ajaxSetup for customizing beforeSend function and modifying outgoing data for AJAX requests

My goal is to develop a universal beforeSend function that modifies the data sent by each jQuery.ajax call. This will allow me to include a custom variable for tracking purposes in every request, regardless of the order they are sent in. For instance, let ...

The README file may appear distorted on npmjs, but it displays correctly on GitHub

In npmjs.com, the readme file is displayed as a binary file, while in github.com it is not. screeshot: Link to the package Github Npmjs ...

Creating a customized form with React Hook Form and Material UI Field Array to store individual values for each field

I am encountering an issue while integrating react-hook-form with MUI. Scenario I am developing a form for users to upload products and select categories. Each main category has sub-categories, but I only need the data of the sub-categories. Users can ch ...

Determine the week number based on a specified starting day for the week

If I have a custom week start day other than Monday, how should the getWeekNumber() prototype for the Date class be modified? Here is the existing code for calculating the ISO Week Number: Date.prototype.getWeekNumber = function() { // Create a dupli ...