首页 > 解决方案 > 找不到 react-google-maps 模块:无法解析“react-google-maps/lib/places/SearchBox”

问题描述

我有一个使用react-google-maps的 create-react-app 。我想要做的是从“react-google-maps/lib/places/SearchBox”导入 SearchBox,但出现以下错误:

Module not found: Can't resolve 'react-google-maps/lib/places/SearchBox' in 'D:\ReactApp\demo\src\components'
import React from 'react';
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps"
import SearchBox from 'react-google-maps/lib/places/SearchBox';

其他进口正常。当我从子目录即 /node_modules/react-google-maps/lib/... 导入模块时,似乎会出现问题。

标签: node-modulescreate-react-appreact-google-maps

解决方案


尝试使用这个:

yarn add react-google-maps-loader --windows
npm install react-google-maps-loader --save

yarn add react-google-maps-loader --windows
npm install react-google-maps-loader --save

推荐阅读