'Puppeteer/Evaluation: Problem with using $x in a puppeteer evaluation script

This following code is meant to grab an elemtn via xpath but I get the following error:

Code:

    async main() {
        await this.initBrowser();
        await this.curPage.goto('https://someurl.com/');
        await this.curPage.evaluate(() => {
            console.log($x('//*Some_Xpath_Query'));
        })
    };

Error:

Error: Evaluation failed: ReferenceError: $x is not defined


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source