Dafrok / vue-baidu-map

Baidu Map components for Vue 2.x
https://dafrok.github.io/vue-baidu-map/
MIT License
2.41k stars 431 forks source link

SSR / BMapLib.TextIconOverlay causes break right away on import #633

Open cjblomqvist opened 5 years ago

cjblomqvist commented 5 years ago

[BUG 反馈] SSR / BMapLib.TextIconOverlay causes break right away on import

浏览器版本号

-

Vue 版本号

2.6.x

组件库版本号

0.21.20

现象描述

When rendering a Vue SSR page with only import XXX from 'vue-baidu-map' it causes exception stopping rendering

完整异常信息

navigator is not defined

This reporting tool is unfortunately so bad I'll have to write more in the actual Github issue when it's been created.

在线示例 / 仓库 URL

www.doesnotexist.com

复现用例

example

预期输出

-

实际输出

-
cjblomqvist commented 5 years ago

More specifically, this is caused by the BMapLib.TextIconOverlay lib, which is used by Lushu and MarkerClusterer. Since everything is imported right away, this causes all SSR to not work. This is unfortunate, as it's best practice to import frontend libs also in SSR build (to avoid having to many different code bases) - even if we are only rendering any map components in the frontend.

A possible workaround seems to be to only import selected modules.

One solution is to not import/export the extra components in the main file.