shukerullah / react-geocode

A React module to transform a description of a location (i.e. street address, town name, etc.) into geographic coordinates (i.e. latitude and longitude) and vice versa.
MIT License
207 stars 33 forks source link

Uncaught TypeError: react_geocode__WEBPACK_IMPORTED_MODULE_2___default.a.setRegion is not a function #39

Closed SaiShangAI closed 3 years ago

SaiShangAI commented 3 years ago

hi @shukerullah I got the error when I want to ser my region. Could you help me with the issue? Many thanks

ziyaddin commented 3 years ago

Hi @SaiShangAI, could you paste here your code where you import the library and use setRegion function?

SaiShangAI commented 3 years ago

hi @ziyaddin I import the library and would like to set the region in a file like this:

import React from 'react';
import {
  GoogleMap,
  InfoWindow,
  KmlLayer,
  Marker,
  withGoogleMap,
  withScriptjs
} from 'react-google-maps';
import Geocode from 'react-geocode';
import * as PropTypes from 'prop-types';

Geocode.enableDebug();
Geocode.setRegion('cn')
Geocode.setApiKey('XXXXXXXXXXXXXX');
......
SaiShangAI commented 3 years ago
Screen Shot 2020-11-04 at 10 59 58 AM

hi @ziyaddin it seems like the function setRegion is not defined

ziyaddin commented 3 years ago

@SaiShangAI could you install @types/react-geocode package and see if it works after that?

SaiShangAI commented 3 years ago

hi @ziyaddin nope, doesn't work

ziyaddin commented 3 years ago
Screen Shot 2020-11-04 at 10 59 58 AM

@SaiShangAI where is this type file located? Can you remove it?

ziyaddin commented 3 years ago

@SaiShangAI the type, you are using, is wrong. The correct one is @types/react-geocode. You should somehow remove the wrong one.

SaiShangAI commented 3 years ago

hi @ziyaddin I removed the react-geocode and install @types/react-geocode. But When I import import Geocode from '@types/react-geocode', the terminal show Module is not found. So I would like to ask If my importing is right? many thanks

Module not found: Can't resolve '@types/react-geocode'

ziyaddin commented 3 years ago

@SaiShangAI you should import Geocode not from @types/react-geocode but react-geocode:

import Geocode from 'react-geocode';

@types/react-geocode will help you with types by suggesting them to you. No need to import this package into your code.

Please, try and inform me if it works.

SaiShangAI commented 3 years ago

hi @ziyaddin I installed @types/react-geocode and react-geocode. But still I don't know how to make Geocode link to the right types.

ziyaddin commented 3 years ago

@SaiShangAI where is the old type file, you showed me via image above, located? By default, each library tries to link to its own @types/bla-bla-bla package.

SaiShangAI commented 3 years ago

hi @ziyaddin the Type definitions for react-geocode 0.2. I installed the version is 0.1.2. Now I use the newest react-geocode version. It works. Many thanks🙏 for your help. Really appreciate.

ziyaddin commented 3 years ago

@SaiShangAI you're welcome.