Reputation: 11
I dont know why getting this error all the time, tryed many times bypass it. Maybe who knowing solution and haved this error?
app.module
NgxMapboxGLModule.withConfig(
{token added..
}),
package
"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)
Upvotes: 1
Views: 958
Reputation: 76
Solution from ngx-mapbox-gl README:
Add this in your polyfill.ts file (https://github.com/Wykks/ngx-mapbox-gl/issues/136#issuecomment-496224634):
(window as any).global = window;
ngx-mapbox-gl depends on sha.js which calls 'global' which isn't available in the browser (it's a Node.js variable). The above code polyfills 'global' to be 'window' (which is available in the browser). Part of the wider range of issues caused by Angular 6 and above removing webpack's polyfills for Node.js specific variables and libraries (crypto, http, etc.)
Angular 6 many Can't resolve errors (crypto, fs, http, https, net, path, stream, tls, zlib)
Related section at bottom of this article
Upvotes: 3