【问题标题】:react-native-google-places-autocomplete unable to resolve module `path/custom/left-icon`react-native-google-places-autocomplete 无法解析模块`path/custom/left-icon`
【发布时间】: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


【解决方案1】:

只要把线拿出来

 renderLeftButton={() => <Image source={require('path/custom/left-icon')} />}

或者将其替换为文本或您自己的图像。您应该将该路径替换为您自己的文本或图像,或者如果您不需要它,您应该将其完全取出。

试试这个例子:

renderLeftButton={() => <Text> Left Button or Left Icon </Text>}

【讨论】:

    【解决方案2】:

    对于那些不使用纱线运行npm start -- --reset-cache 的人,如果它显示错误“模块无法侦听端口 8081”,请尝试终止所有正在侦听/使用该端口的进程。对于 mac,通过运行 sudo lson -i :8081 获取进程 ID,然后杀死每个进程 kill -9 pid

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 2019-10-12
      • 2017-10-11
      • 2016-03-23
      • 1970-01-01
      • 2020-05-27
      相关资源
      最近更新 更多