我在以下位置得到此错误:从'mqtt'导入mqtt
ERROR
Buffer is not defined
ReferenceError: Buffer is not defined
at ./node_modules/mqtt-packet/constants.js (http://localhost:3000/static/js/bundle.js:39648:34)
at options.factory (http://localhost:3000/static/js/bundle.js:103411:31)
at __webpack_require__ (http://localhost:3000/static/js/bundle.js:102835:33)
at fn (http://localhost:3000/static/js/bundle.js:103068:21)
at ./node_modules/mqtt-packet/parser.js (http://localhost:3000/static/js/bundle.js:39937:19)
at options.factory (http://localhost:3000/static/js/bundle.js:103411:31)
at __webpack_require__ (http://localhost:3000/static/js/bundle.js:102835:33)
at fn (http://localhost:3000/static/js/bundle.js:103068:21)
at ./node_modules/mqtt-packet/mqtt.js (http://localhost:3000/static/js/bundle.js:39844:18)
at options.factory (http://localhost:3000/static/js/bundle.js:103411:31)
1条答案
按热度按时间9jyewag01#
这是因为mqtt.js是一个node.js包,而不是浏览器包。使用https://www.npmjs.com/package/mqtt-browser即可。