I've got an Angular web-scraping project that I'm trying to use Cheerio in. I have included Cheerio into my angular.json
file. When I include Cheerio into my App component I get the following error message:
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)
I fixed this error by typing this into index.html
as @Leandro Matilla suggested:
if (global === undefined) {
var global = window;
}
But now I get a different error:
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)
How do I fix this error message? I've tried other solutions on StackOverflow, but none of them have worked...