【发布时间】:2020-11-19 12:32:48
【问题描述】:
我有一个带有 mapbox-gl 的 gatsby.js 应用程序,在我尝试包含 mapbox-gl-geocoder 包以添加搜索功能之前,它都可以成功运行。
我已经使用 npm 安装了它,如下所示:
npm install mapbox/mapbox-gl-geocoder --save
然后,将其添加到 React 组件中:
import '@mapbox/mapbox-gl-geocoder/lib/mapbox-gl-geocoder.css';
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
在 useEffect 钩子中:
map.addControl(
new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
zoom: 20,
placeholder: 'Enter City',
mapboxgl: mapboxgl
}), 'top-left'
);
在本地,当我运行 gatsby develop 时,它可以正常工作,但是当我使用 Netlify 部署它时,出现以下错误:
:24:21 PM: error Generating SSR bundle failed
1:24:21 PM: Can't resolve 'electron' in '/opt/build/repo/node_modules/@mapbox/mapbox-sdk/node_modules/got'
1:24:21 PM: If you're trying to use a package make sure that 'electron' is installed. If you're trying to use a local file make sure that the path is correct.
似乎 mapbox-gl-geocoder 对 @mapbox/mapbox-sdk 有依赖关系,而 mapbox-sdk 有依赖关系以某种方式需要电子?
在 got npm 页面中我唯一能读到的关于电子的内容如下:
Electron support has been removed
The Electron net module is not consistent with the Node.js http module. See #899 for more info.
无论如何,我尝试使用 npm 安装 electron 以查看错误是否消失,并且构建开始失败并出现新错误,表明窗口对象不可用。
10:35:45 AM: error "window" is not available during server side rendering.
谷歌搜索该错误导致我得到了一些关于未在 gatsby-node.js 中加载包的答案,但这也无济于事。
【问题讨论】:
标签: mapbox gatsby netlify mapbox-gl