У меня есть Angular веб-проект, в котором я пытаюсь использовать Cheerio. Я включил Cheerio в свой файл angular.json
. Когда я включаю Cheerio в свой компонент приложения, я получаю следующее сообщение об ошибке:
index.js:43 Uncaught ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/readable-stream/node_modules/safe-buffer/index.js (index.js:2)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:55)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/readable-stream/readable-browser.js (readable-browser.js:1)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/stream-browserify/index.js (index.js:28)
at __webpack_require__ (bootstrap:79)
Я исправил эту ошибку, набрав ее в index.html
, как предложил @Leandro Matilla:
if (global === undefined) {
var global = window;
}
Но теперь я получаю другую ошибку:
util.js:103 Uncaught ReferenceError: Buffer is not defined
at Object../node_modules/core-util-is/lib/util.js (util.js:103)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:67)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/readable-stream/readable-browser.js (readable-browser.js:1)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/stream-browserify/index.js (index.js:28)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/cheerio/node_modules/parse5/lib/parser/parser_stream.js (parser_stream.js:3)
at __webpack_require__ (bootstrap:79)
Как мне исправить это сообщение об ошибке? Я пробовал другие решения на StackOverflow, но ни одно из них не сработало ...