huiyan-fe / react-bmap

基于百度地图JavaScript API封装的React组件库
http://huiyan-fe.github.io/react-bmap
MIT License
497 stars 97 forks source link

BMap is not defined in /react-bmap/lib/overlay/CustomOverlay.js #4

Closed williamli closed 7 years ago

williamli commented 7 years ago

when

import {Map, Marker, NavigationControl, InfoWindow} from 'react-bmap';

I get BMap is not defined

20170825-10:50:52.498(8)? (STDERR) ReferenceError: BMap is not defined
W20170825-10:50:52.499(8)? (STDERR)     at Object.<anonymous> (#####/node_modules/react-bmap/lib/overlay/CustomOverlay.js:13:31)
W20170825-10:50:52.499(8)? (STDERR)     at Module._compile (module.js:409:26)
W20170825-10:50:52.500(8)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)
W20170825-10:50:52.500(8)? (STDERR)     at Module.load (module.js:343:32)
W20170825-10:50:52.501(8)? (STDERR)     at Function.Module._load (module.js:300:12)
W20170825-10:50:52.502(8)? (STDERR)     at Module.require (module.js:353:17)
W20170825-10:50:52.502(8)? (STDERR)     at require (internal/module.js:12:17)
W20170825-10:50:52.503(8)? (STDERR)     at Object.<anonymous> (#####/node_modules/react-bmap/lib/components/marker.js:13:22)
W20170825-10:50:52.504(8)? (STDERR)     at Module._compile (module.js:409:26)
W20170825-10:50:52.505(8)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)
=> Exited with code: 1
zmofei commented 7 years ago

BMap is from Baidu map SDK, you should import Baidu SDK first.

williamli commented 7 years ago

@zmofei which npm modules is the Baidu map SDK in?

zmofei commented 7 years ago

you can get Baidu map SDK from http://lbsyun.baidu.com/, then you can import the SDK from the URL http://api.map.baidu.com/api?v=2.0&ak=YOUR_SDK.

eg:

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=YOUR_SDK"></script>
<script>
   // ... your code
</script>
williamli commented 7 years ago

I have that on the browser side. I am using Meteor + React and the server is crashing because BMap is not defined there. Let me see if Baidu map SDK has a npm package.

screen shot 2017-08-25 at 11 19 21

williamli commented 7 years ago

Problem solved. I had to stop importing react-bmap at run time to prevent the server from picking it up.

It can then be loaded in the browser once Baidu SDK is loaded in the browser the functions using require or dynamic import.'

FateZeros commented 6 years ago

@williamli I have the same problem. How do you solve it

DANIEL73H commented 1 year ago

@williamli I already install vue-baidu-map,but still have this problem;