我不知道为什么每次都会收到此错误,并尝试多次绕过它。 也许谁知道解决方案并遇到了这个错误?
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)
答案 0 :(得分:2)
来自ngx-mapbox-gl README的解决方案:
将此添加到您的polyfill.ts文件中 (https://github.com/Wykks/ngx-mapbox-gl/issues/136#issuecomment-496224634):
(任意窗口).global = window;
ngx-mapbox-gl依赖于sha.js,后者调用的“全局”在浏览器中不可用(这是一个Node.js变量)。上面的代码将'global'填充为'window'(在浏览器中可用)。 Angular 6和更高版本所引起的一系列问题中的一部分,它删除了针对Node.js特定变量和库(密码,http等)的webpack的polyfills
Angular 6 many Can't resolve errors (crypto, fs, http, https, net, path, stream, tls, zlib)