angular - Mapbox not works global 未定义
问题描述
我不知道为什么总是得到这个错误,尝试了很多次绕过它。也许谁知道解决方案并有这个错误?
应用程序模块
NgxMapboxGLModule.withConfig(
{token added..
}),
包裹
"mapbox-gl": "^0.52.0",
"ngx-mapbox-gl": "^3.0.1",
"@types/mapbox-gl": "^0.51.4",
"@mapbox/geojson-area": "^0.2.2",
"@mapbox/mapbox-gl-geocoder": "^3.1.6",
"@mapbox/simplespec-to-gl-style": "^0.3.2",
index.js:43 Uncaught ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/safe-buffer/index.js (index.js:2)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/sha.js/hash.js (hash.js:1)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/sha.js/sha.js (sha.js:10)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/sha.js/index.js (index.js:10)
at __webpack_require__ (bootstrap:79)
解决方案
来自ngx-mapbox-gl README 的解决方案:
将此添加到您的 polyfill.ts 文件中(https://github.com/Wykks/ngx-mapbox-gl/issues/136#issuecomment-496224634):
(window as any).global = window;
ngx-mapbox-gl 依赖于 sha.js,它调用在浏览器中不可用的“全局”(它是一个 Node.js 变量)。上面的代码将 'global' 填充为 'window' (在浏览器中可用)。Angular 6 及更高版本为 Node.js 特定变量和库(加密、http 等)删除 webpack 的 polyfill 导致的更广泛问题的一部分
Angular 6 many Can't resolve errors (crypto, fs, http, https, net, path, stream, tls, zlib)
推荐阅读
- websocket - WebSocket 协议在 TCP/IP 模型中的位置?
- android - 虽然每次在 sql server 2018 上都会出现使用 IP 地址超时错误登录
- java - 通过使用 Java (JAXB) 读取 XML 来获取现有对象
- php - PHPUnit - Mockery::mock vs Mockery::namedMocks
- jbpm - 即使在全新安装产品时也无法访问 Business Central/Decision Central 并显示消息“请等待加载应用程序”
- java - 我想在java中查找文件是否存在
- mysql - MYSQL 高 CPU 使用率和慢查询
- python - 在 pandas 中,如何通过多列的组合设置索引?
- amazon-web-services - AWS StepFunction 与 Invoke Child Workflow 状态使用云形成让步
- build - 无法构建 Skia 模块 (SkPlainTextEditor)