我将我的项目从 angular-5.x 升级到 angular-6.x,它开始出现以下错误,甚至创建虚拟全局变量也无法像这里给出的那样工作 Angular 6 Auth0 - 全局未定义
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
错误如下:
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)然后继续下去.
推荐答案在起始页中添加以下代码,例如index.html
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: [] };示例:
<!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>以上将适用于混合应用程序(在 Node 环境中)以及浏览器
Above will work on hybrid app (in Node environment) as well as in browser
对于未捕获的引用错误:全局未定义":
for "Uncaught ReferenceError: global is not defined": var global = global || window;
对于未捕获的引用错误:缓冲区未定义":
for "Uncaught ReferenceError: Buffer is not defined":
var Buffer = Buffer || [];对于未捕获的引用错误:进程未定义":
for "Uncaught ReferenceError: process is not defined":
var process = process || { env: { DEBUG: undefined } }对于未捕获的类型错误:无法读取未定义的属性‘切片’":
for "Uncaught TypeError: Cannot read property 'slice' of undefined":
var process = process || { env: { DEBUG: undefined }, version: [] };
更多推荐
升级到 angular
发布评论