javascript - 升级到 angular-6.x 得到 "Uncaught ReferenceError: global is not defined"

标签 javascript angular angular-cli angular6

我将我的项目从 angular-5.x 升级到 angular-6.x,它开始出现以下错误,甚至创建虚拟全局变量也不起作用,如此处所示 Angular 6 Auth0 - global not defined

错误如下:

Uncaught ReferenceError: global is not defined
    at Object../node_modules/has-binary2/index.js (index.js:10)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/socket.io-parser/index.js (index.js:8)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/socket.io-client/lib/index.js (index.js:7)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/app4pc/apiConnection/services/ApiConnectionServer.ts (auth.interceptor.ts:8)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/app4pc/apiConnection/toServer.module.ts (ApiConnectionServer.ts:11)
    at __webpack_require__ (bootstrap:81)

解决此问题后出现以下错误:

Uncaught ReferenceError: process is not defined
    at Object../node_modules/process-nextick-args/index.js (index.js:3)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:26)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/readable-stream/readable-browser.js (readable-browser.js:1)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/simple-peer/index.js (index.js:7)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/util/services/call.services.ts (notification.service.ts:12)
    at __webpack_require__ (bootstrap:81)    

并继续下去。

最佳答案

将此行添加到 polyfills.ts 应该可以解决节点全局错误

(window as any).global = window;

这个angular-cli issue thred中提到了解决方案

关于javascript - 升级到 angular-6.x 得到 "Uncaught ReferenceError: global is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50356408/

相关文章:

javascript - 隐藏具有相同类或 ID 的第二个元素

android - 如何将使用 Angular v7 的 Web 应用程序迁移到移动 NativeScript 应用程序

angular - Angular 错误处理和日志记录-调用GlobalErrorHandler的handleError

angular - 从现有项目构建 Angular 元素

angular - 为index.html中的src标签指定前缀

angular - 错误 rxjs_Observable__.Observable.forkJoin 不是函数?

javascript - 如何在 RequireJS 中为模块分配变量?

javascript - 如何使用 lodash 从对象中删除未定义值和空值?

javascript - Node.JS fork 管道

angular - 运行单个测试文件