Angular 10 : Buffer is not defined

标签 angular amqp node-amqp

我需要一些帮助,因为我不知道该怎么做。我必须在我的 Angular 项目中使用“amqplib”。首先,我尝试使用“amqp-ts”,但一旦打开浏览器,我就遇到错误:Buffer is not defined

经过几次尝试,我切换到了“amqplib”。但是,当我尝试调用库的函数时出现错误:Second error

错误发生在一行:

if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  module.exports = buffer
} else {
  // Copy properties from require('buffer')
  copyProps(buffer, exports)
  exports.Buffer = SafeBuffer
}

同样,Buffer 没有定义。

我已经尝试了这里提到的几种解决方案:Angular 6 Uncaught ReferenceError: Buffer is not defined我最终得到了: -安装的“缓冲”包

-在 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: ''
};

-in index.html

<script>
    var global = global || window;
</script>

然而,他们都没有帮助,我仍然有这些错误:/

最佳答案

我正在尝试使用加密浏览器

我也最终使用 npm 安装了 Buffer 包

然后我收到一个错误:- Buffer is not a constructor 这是我所做的-

在 polyfills.ts 中 -

import * as Buffer from '../node_modules/buffer/index';
(window as any).global = window;
(window as any).process = {};
(window as any).process = window;
(window as any).process.browser = true;
(window as any).process.version = '';
(window as any).process.versions = { node: false };
(window as any).global.Buffer = Buffer.Buffer;

关于 Angular 10 : Buffer is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63622248/

相关文章:

来自 Vertx 和 AMQPBridge 的 Java 运行时警告

angular - 从 ts 页面重置 p 表

css - 带 ionic 2 的 bootstrap-sass

angular - 您如何确定是什么触发了 Angular2 中的变化检测检测(调试 ngDoCheck 无限循环)?

angular - vendor.bundle.js 中捆绑了什么?

c - 如何检查消息是否传递到任何单个队列

go - 路由键不匹配,但消息仍被发送到队列

node.js - 我可以从我的 NodeJS 应用动态创建 RabbitMQ 铲吗?

node.js - RabbitMQ/AMQP : single queue, 同一消息的多个消费者?

node.js - 在 node-amqp (node.js) 中处理独占队列订阅时出错