我将我的项目从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) 我需要一些帮助,因为我不知道该怎么做。我必须在我的 Angular 项目中使用“amqplib”。首先,我尝试使用“amqp-ts”,但是当我打开浏览器时,我遇到了错误:
经过几次尝试,我已切换到“amqplib”。但是,当我尝试调用库的函数时,出现错误:
错误发生在以下行:
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
module.exports = buffer
} else {
// Copy properties from require('buffer')
copyProps(buffer, exports)
exports.Buffer = SafeBuffer
}
Run Code Online (Sandbox Code Playgroud)
同样,Buffer 没有定义。
我已经尝试了这里提到的几种解决方案:Angular 6 Uncaught ReferenceError: Buffer is not Defined,我最终得到:-installed 'buffer' package
- 在polyfills.ts中
declare var require: any;
declare var global: any;
(window as any).global = window;
// @ts-ignore
window.Buffer = window.Buffer || require('buffer').Buffer;
(window as any).process = {
version: ''
};
Run Code Online (Sandbox Code Playgroud)
-在index.html中
<script>
var global = …Run Code Online (Sandbox Code Playgroud)