Using amqplib in vue will report the error Uncaught ReferenceError: Buffer is not defined

This error is caused by a missing Buffer object in the Vue project. The amqplib library needs to use Buffer objects to process binary data at runtime, and in the Vue project, the Buffer objects may not be introduced correctly.

There are two solutions:

  1. Introduce the Buffer object in the main.js file, such as:
    global.Buffer = global.Buffer || require('buffer').Buffer
    

2. Add the following configuration to the webpack.config.js file:

node: {
    Buffer: true
  }

This way you can use amqplib in vue.

Guess you like

Origin blog.csdn.net/weixin_35756892/article/details/129081739
Recommended