Ati*_*man 47 javascript angular-cli angular angular6
我将我的项目从angular-5.x升级到angular-6.x并且它开始给出以下错误,甚至创建虚拟全局变量也不起作用,如此处给出Angular 6 Auth0 - 全局未定义
错误如下:
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)
Run Code Online (Sandbox Code Playgroud)
解决这个后,我得到以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
并继续下去.
Voj*_*ech 75
添加此行polyfills.ts应解决节点全局错误
(window as any).global = window;
在这个角度cli问题中提到了解决方案
Akh*_*mar 74
在您的起始页面中添加以下代码,例如index.html
var global = global || window;
var Buffer = Buffer || [];
var process = process || {
env: { DEBUG: undefined },
version: []
};
Run Code Online (Sandbox Code Playgroud)
例如:
<!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>
Run Code Online (Sandbox Code Playgroud)
以上将适用于混合应用程序(在节点环境中)以及浏览器中
__CODE__// for Uncaught ReferenceError:未定义global
__CODE__// for Uncaught ReferenceError:未定义Buffer
__CODE__// for Uncaught ReferenceError:未定义进程
__CODE__// Uncaught TypeError:无法读取未定义的属性"slice"
我使用HttpClient并意外选择了默认导入'selenium-webdriver/http'
如果您的app.module.ts有 import { HttpClient } from 'selenium-webdriver/http';
更新到 import { HttpClient } from '@angular/common/http';
那解决了我的问题。
| 归档时间: |
|
| 查看次数: |
27098 次 |
| 最近记录: |