Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  26] [ 2]  / answers: 1 / hits: 64844  / 6 Years ago, tue, may 15, 2018, 12:00:00

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.


More From » angular

 Answers
35

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: []
};


Example:



<!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





  • 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: []
    };



[#54426] Friday, May 11, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
johnnyblaynes

Total Points: 667
Total Questions: 121
Total Answers: 102

Location: Anguilla
Member since Sat, Jan 23, 2021
3 Years ago
;