【问题标题】:Mapbox not works global is not definedMapbox not works global 未定义
【发布时间】:2019-10-24 17:57:48
【问题描述】:

我不知道为什么总是出现这个错误,尝试了很多次绕过它。 也许谁知道解决方案并出现此错误?

app.module

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)

【问题讨论】:

    标签: angular mapbox


    【解决方案1】:

    来自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)

    Related section at bottom of this article

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-09
      • 2018-06-01
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多