"TypeError: (intermediate value).on is not a function" when trying to use SiteChecker
thomaspaulin opened this issue · 3 comments
thomaspaulin commented
Describe the bug
on(...)
is not a function on the SiteChecker
object.
To Reproduce
- Set up a Node project
- Install broken-link-checker with the npm command listed on the project readme -
npm install broken-link-checker
- Copy the code snippet for a
SiteChecker
from the readme intoindex.js
.
const {SiteChecker} = require('broken-link-checker');
const siteChecker = new SiteChecker({})
.on('error', (error) => {})
.on('robots', (robots, customData) => {})
.on('html', (tree, robots, response, pageURL, customData) => {})
.on('queue', () => {})
.on('junk', (result, customData) => {})
.on('link', (result, customData) => {})
.on('page', (error, pageURL, customData) => {})
.on('site', (error, siteURL, customData) => {})
.on('end', () => {});
siteChecker.enqueue("https://www.google.com", undefined);
- Run
node index.js
- Notice the error message
Expected behavior
I did not expect this error. I expected the readme code to work.
Environment:
- OS and version: macOS Mojave (14.10.6)
- Node.js version: v14.15.3
- broken-link-checker version: ^0.7.8
matthamil commented
I ran into the same issue. You don't call a .on
method, but pass a second argument to the constructor to set these callbacks:
const handlers = {
error: (error) => {},
robots: (robots, customData) => {},
// ...
}
const siteChecker = new SiteChecker(options, handlers)
thomaspaulin commented
Thanks @matthamil that work around...works! It doesn't fix the wrong documentation though.
stevenvachon commented
Thanks @matthamil that work around...works! It doesn't fix the wrong documentation though.
Not if you use the published npm readme instead of the git trunk.