我试图创建一个项目的反应,显示谷歌地图与不同的位置。
我使用了:$ npm install --save google-map-react,这是我在网上找到的非常简单的教程:https://dev.to/jessicabetts/how-to-use-google-maps-api-and-react-js-26c2。
但后来我意识到有两个类似的npm安装:
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);发布于 2020-04-11 20:30:11
基于本教程,您似乎错过了关键的一步。
您需要在项目中安装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发布于 2022-01-12 09:36:53
我也有过同样的问题。我通过在文件declare module 'google-map-react'中添加react-app-env.d.ts来修正它
试一试,按照我使用TS和React的方式给出反馈
https://stackoverflow.com/questions/61163284
复制相似问题