boxrec: Uncaught TypeError TypeError: $ is not a function When trying to get "output" or "links"

Hi @mikedidomizio I really appreciated your effort to upgrade this package continuously.

Btw, I found this error when I tried to get "output" or "links" field.

This is my code.

let schedules = await boxrec.getSchedule(cookieJar, {
    countryCode: '',
});
console.log(schedules.events[0].bouts[0].links);

... OR

let schedules = await boxrec.getDate(cookieJar, {
    day: 19,
    month: 4,
    year: 2022
});
console.log(schedules.output.events[0].bouts[0].output);

And when I try to access to the “links” or “output” field to get bout_id like above ones, it just gives this error for some reason. I was able to access to them in the previous version but they were just null for some reason.

Uncaught TypeError TypeError: $ is not a function
    at o.parseLinksColumn (c:\boxrec\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:353)
    at <anonymous> (c:\boxrec\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:243)
    at each (c:\boxrec\node_modules\cheerio\lib\api\traversing.js:480:26)
    at o.parseLinkInformation (c:\boxrec\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:216)
    at get (c:\boxrec\node_modules\boxrec\dist\boxrec-pages\event\boxrec.page.event.bout.row.js:1:2308)
...

Not sure If I will need to install another package with boxrec package.

Could you please check this issue? Thanks

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Great It worked as a charm.

Thank you very much

Hi @mikedidomizio

Thanks for the updates. But it still doesn’t appear working.

I made a very simple script as it still gave the errors on my old code. This is my simple script.

const boxrec = require("boxrec").Boxrec;

(async() => {
    try {
        const BOXREC_USERNAME = process.env.BOXREC_USERNAME;
        const BOXREC_PASSWORD = process.env.BOXREC_PASSWORD;
        const cookie = await boxrec.login(BOXREC_USERNAME, BOXREC_PASSWORD);

        let schedules = await boxrec.getSchedule(cookie, {
            countryCode: '',
        });
        console.log(schedules.events[0].bouts[0].links);

        let schedules2 = await boxrec.getDate(cookie, {
            day: 19,
            month: 4,
            year: 2022
        });
        console.log(schedules2.output.events[0].bouts[0].output);

        console.log('done')
    } catch(e) {
        console.log(e)
    }
})();

And this is my package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "boxrec": "^8.0.1",
    "form-data": "^4.0.0"
  }
}

Please note that I also installed form-data package because it gave an error (Cannot find module form-data) when I installed only the boxrec package.

When I run the code, I can still see this error.

TypeError: $ is not a function
    at Function.o.parseLinksColumn (C:\test\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:353)
    at Node.<anonymous> (C:\test\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:243)
    at LoadedCheerio.each (C:\test\node_modules\cheerio\lib\api\traversing.js:480:26)
    at Function.o.parseLinkInformation (C:\test\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:216)
    at e.get [as links] (C:\test\node_modules\boxrec\dist\boxrec-pages\event\boxrec.page.event.bout.row.js:1:2308)
    at C:\test\index.js:12:50
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Thanks

Let’s try boxrec@8.0.3. I think it was the way CheerioJS was imported for that file and not loaded like the others. It doesn’t explain why it worked for me and not for you but I’m hoping this gets us past the problem you’re seeing.

Hey there,

Can you try boxrec@8.0.2? I’ve added form-data to boxrec-requests. I think it appeared fine to me but was actually a problem.

I never experienced the Cheerio errors you experienced. Which is weird.

If you still experience errors, give me whatever script you’re using.

I published 8.0.1, that I hope addresses the problem.

This was my testing script, and perhaps in the future I’ll ask for the script beforehand.

const {Boxrec} = require("boxrec");

(async() => {
    try {
        const cookie = await Boxrec.login(process.env.BOXREC_USERNAME, process.env.BOXREC_PASSWORD);

        let schedules = await Boxrec.getSchedule(cookie, {
            countryCode: '',
        });
        console.log(schedules.events[0].bouts[0].links);

        let schedules2 = await Boxrec.getDate(cookie, {
            day: 19,
            month: 4,
            year: 2022
        });
        console.log(schedules2.output.events[0].bouts[0].output);

        console.log('done')
    } catch(e) {
        console.log(e)
    }
})();

this was the after output (good links)

{ bio: 2832562, bout: '853786/2832562', other: [] }
{
  division: 'welterweight',
  firstBoxer: { id: 1086023, name: 'Kagan Kanlibilge' },
  firstBoxerLast6: [],
  firstBoxerRecord: { draw: 0, loss: 0, win: 0 },
  firstBoxerWeight: null,
  links: { bio: 2831984, bout: '853662/2831984', other: [] },
  metadata: '2022 EUBC European Youth Championships Quarter-Final\n<br>',
  numberOfRounds: [ 3, 3 ],
  outcome: 'win',
  outcomeByWayOf: 'SD',
  rating: 20,
  secondBoxer: { id: 1066608, name: 'Jim Donovan' },
  secondBoxerLast6: [ 'win', 'win', 'win', 'win', 'win', 'win' ],
  secondBoxerRecord: { draw: 0, loss: 1, win: 9 },
  secondBoxerWeight: null,
  sport: 'am boxing'
}
done

Otherwise if this doesn’t fix it send me the exact script and expected outputs. Anything else as well.

Then wait.

I haven’t had time to look at it. Will comment here when there is an update.

Thanks for your checking the issue.

This is my code I just tested with.

let schedules = await boxrec.getDate(cookieJar, {
      day: 21,
      month: 4,
      year: 2022
 });

And the response is like this. image

Then I tried to get the first bout of the first event. schedules.events[0].bouts[0]

image

Lastly I tried to get the output of the bout, then it throws this error. schedules.events[0].bouts[0].output

Uncaught TypeError TypeError: $ is not a function
    at o.parseLinksColumn (c:\boxrec\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:353)
    at <anonymous> (c:\boxrec\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:243)
    at each (c:\boxrec\node_modules\cheerio\lib\api\traversing.js:480:26)
    at o.parseLinkInformation (c:\boxrec\node_modules\boxrec\dist\boxrec-common-tables\boxrec-common-links.js:1:216)
    ....

When I tried to get the links directly, it was also giving the same error above. schedules.events[0].bouts[0].links

I also confirmed I am using the latest version(8.0.0).

Thanks

Okay,

  • So schedule may need some fixing for links
  • With getDate, output may be broken. The problem with output is that it has to grab all the data, and if one is to throw, it in fact wrecks everything.

TypeError: $ is not a function - means it’s an issue with Cheerio coming fromboxrec-common-links. If I had to quickly guess it’s probably here which is the issue. Almost guaranteed.

Not sure If I will need to install another package with boxrec package.

Nope, the package should work alone. All the links pass through that class I posted above for parsing. When output is working, it’s great, when it’s not, well the fallback is to get individual chunks of info. Although that might not matter in this scenario.

No ETA on this. Hopefully sooner, but probably a few weeks. Just due to other projects and life. There’s enough information in this comment that someone could pick it up and fix it though.