I am completely new to JS, and got completely stuck at the Node Cheerio. I would really appreciate if anyone could help me.
The code I am working on is here: https://github.com/zafartahirov/bitstarter.
(The code that doesn't work will be called grader.old.js after the fix is found).
When I run
node ./grader.js --file index.html --checks checks.json | less
I receive an error:
TypeError: Cannot call method 'utf8Slice' of null
at Buffer.toString (buffer.js:416:26)
at exports.isTag (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/utils.js:15:14)
at Function.filter (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/node_modules/lodash/dist/lodash.js:3150:15)
at /home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/api/traversing.js:9:26
at Function.reduce (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/node_modules/lodash/dist/lodash.js:3734:25)
at exports.find (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/api/traversing.js:8:17)
at new module.exports (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/cheerio.js:92:18)
at initialize (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/static.js:23:12)
at checkHtmlFile (/home/ubuntu/GitHub/bitstarter/grader.js:59:23)
at Object.<anonymous> (/home/ubuntu/GitHub/bitstarter/grader.js:76:21)
(END)
Any suggestions?
We are taking the same course, and it took me quite some time to debug it.
It seems the cheerio.load()
method expects a String as an argument and not a buffer.