【问题标题】:Module not found: Can't resolve 'google-maps-react' in 'C:\Users\USUARIO未找到模块:无法解析“C:\Users\USUARIO”中的“google-maps-react”
【发布时间】:2020-04-11 20:28:14
【问题描述】:

我正在尝试在 react 中创建一个显示具有不同位置的谷歌地图的项目。

我在网上找到的这个非常简单的教程中使用了:$ npm install --save google-map-react:https://dev.to/jessicabetts/how-to-use-google-maps-api-and-react-js-26c2。

但后来我发现有2个类似的npm install:

  1. 保存谷歌地图反应
  2. 保存 google-maps-react

我很困惑!我总是遇到同样的错误:

./src/components/MapContainer.js
Module not found: Can't resolve 'google-maps-react' in 'C:\Users\USUARIO\OneDrive\Escritorio\ProyectosGA\react-geek\packyfood\src\components'

我不知道如何解决它,也没有太多信息。你们能帮帮我吗?这是我的代码:

MapContainer.js

import React, { Component } from 'react';
import { Map, GoogleApiWrapper } from 'google-maps-react';

const mapStyles = {
  width: '100%',
  height: '100%'
};

export class MapContainer extends Component {
  render() {
    return (
      <Map
        google={this.props.google}
        zoom={4}
        style={mapStyles}
        initialCenter={{
         lat: 6.2518401,
         lng: -75.563591
        }}
      />
    );
  }
}

export default GoogleApiWrapper({
  apiKey: 'AIzaSyDGArUEBa5ns09IA7nt7jP-xfNIUkToFts'
})(MapContainer);

【问题讨论】:

    标签: javascript reactjs


    【解决方案1】:

    根据本教程,您似乎错过了关键步骤。

    你需要在你的项目中安装google-maps-react 依赖。

    在您的控制台中,导航到您的项目根目录并运行以下命令:

    npm install --save google-maps-react
    

    对于那些被卡住的人来说,另一个故障排除问题是删除您的 node_modules 文件夹并在控制台中运行 npm install。

    这将为您的项目重新安装所有必需的依赖项。


    注意:

    考虑到您不小心安装了google-map-react 而不是google-maps-react。我建议卸载google-map-react,因为它没有被使用。

    通过在控制台中运行以下命令来做到这一点:

    npm uninstall --save google-map-react
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。我通过添加declare module 'google-map-react' 来修复它;在文件react-app-env.d.ts

      尝试一下,通过我在 React 中使用 TS 的方式给出反馈

      【讨论】:

        猜你喜欢
        • 2019-10-12
        • 1970-01-01
        • 2021-06-06
        • 1970-01-01
        • 1970-01-01
        • 2018-09-21
        • 1970-01-01
        • 2020-11-02
        • 1970-01-01
        相关资源
        最近更新 更多