升级到angular

编程入门 行业动态 更新时间:2024-10-22 21:40:16
本文介绍了升级到angular-6.x会出现“Uncaught ReferenceError:global is not defined”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将我的项目从angular-5.x升级到angular-6.x并且它开始给出以下错误,甚至创建虚拟全局变量也不起作用,如此处给出 Angular 6 Auth0 - 全局未定义

错误如下:

未捕获的ReferenceError:未定义全局 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)

解决此问题后我收到以下错误:

未捕获的ReferenceError:进程未定义 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)

并一直持续。

解决方案

在起始页面中添加以下代码,例如index.html

var global = global ||窗口; var Buffer = Buffer || []; var process = process || { env:{DEBUG:undefined}, version:[] };

例如。如下:

<!doctype html> < html lang =en> < head> < meta charset =utf-8> < title>客户< / title> < base href =/> < meta name =viewportcontent =width = device-width,initial-scale = 1> < link rel =icontype =image / x-iconhref =favicon.ico> < script> var global = global ||窗口; var Buffer = Buffer || []; var process = process || { env:{DEBUG:undefined}, version:[] }; < / script> < / head> < body> < app-root> < div class =loader>< / div> < / app-root> < / body> < / html>

以上将适用于混合应用程序(在节点环境中)以及浏览器中

  • var global = global || window; // for Uncaught ReferenceError:global is not defined

  • var Buffer = Buffer || []; //未捕获的ReferenceError:未定义缓冲区

  • var process = process || { env:{DEBUG:undefined} } //对于Uncaught ReferenceError:进程未定义

  • var process = process || { env:{DEBUG:undefined}, version:[] }; // Uncaught TypeError:无法读取未定义的属性'slice'

I upgraded my project from angular-5.x to angular-6.x and it started giving the following error and even creation of dummy global variable does not work as given here Angular 6 Auth0 - global not defined

The error is as follows:

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)

after resolving this I get following error:

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)

And continues on and on.

解决方案

Add following code in your starting page e.g. index.html

var global = global || window; var Buffer = Buffer || []; var process = process || { env: { DEBUG: undefined }, version: [] };

e.g. follows:

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Client</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> <script> var global = global || window; var Buffer = Buffer || []; var process = process || { env: { DEBUG: undefined }, version: [] }; </script> </head> <body> <app-root> <div class="loader"></div> </app-root> </body> </html>

Above will work on hybrid app(in node environment) as well as in browser

  • var global = global || window; // for Uncaught ReferenceError: global is not defined

  • var Buffer = Buffer || []; // for Uncaught ReferenceError: Buffer is not defined

  • var process = process || { env: { DEBUG: undefined } } // for Uncaught ReferenceError: process is not defined

  • var process = process || { env: { DEBUG: undefined }, version: [] }; // Uncaught TypeError: Cannot read property 'slice' of undefined

更多推荐

升级到angular

本文发布于:2023-06-04 08:34:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/493339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:升级到   angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!