【发布时间】:2018-01-14 23:27:15
【问题描述】:
我无法使用 react native 自动完成 npm 包,并且收到此错误“react-native-google-places-autocomplete 无法解析模块path/custom/left-icon”
我正在使用 react Native V0.44.0
我做错了什么?
import React from 'react';
import { View, Image } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const homePlace = { description: 'Home', geometry: { location: { lat: 48.8152937, lng: 2.4597668 } }};
const workPlace = { description: 'Work', geometry: { location: { lat: 48.8496818, lng: 2.2940881 } }};
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
minLength={2}
autoFocus={false}
returnKeyType={'search'}
listViewDisplayed='auto'
fetchDetails={true}
renderDescription={(row) => row.description}
onPress={(data, details = null) => {
console.log(data);
console.log(details);
}}
getDefaultValue={() => {
return '';
}}
query={{
key: 'YOUR API KEY',
language: 'en',
types: '(cities)'
}}
styles={{
description: {
fontWeight: 'bold'
},
predefinedPlacesDescription: {
color: '#1faadb'
}
}}
currentLocation={true}
currentLocationLabel="Current location"
nearbyPlacesAPI='GooglePlacesSearch'
GoogleReverseGeocodingQuery={{
}}
GooglePlacesSearchQuery={{
rankby: 'distance',
types: 'food'
}}
filterReverseGeocodingByTypes={['locality', 'administrative_area_level_3']}
predefinedPlaces={[homePlace, workPlace]}
debounce={200}
renderLeftButton={() => <Image source={require('path/custom/left-icon')} />}
renderRightButton={() => <Text>Custom text after the inputg</Text>}
/>
);
}
【问题讨论】:
-
您能否编辑您的问题以包含您的文件? (GooglePlacesInput.js)
-
@Bill,感谢您通知我。我已经编辑了我的问题以包含该问题
-
对我来说看起来很正常,也许在项目根目录中尝试
rm -rf node_modules,然后运行yarn,然后运行yarn start --reset-cache?顺便说一句,您使用的是什么版本的自动完成功能? (应该在package.json文件中说) -
感谢您的帮助。我已经解决了
标签: react-native