JavaScript crawler .push() and pop() method works in terminal but returns error in console

For the past month or so I have been trying to learn JavaScript in order to make a web crawler for local music venues in my hometown, things had been going great as the crawler worked perfectly in the terminal

However when I established an Apache web server, integrated some HTML and tried running the code in my browser, my array prints in the console, as "undefined" and I receive a "Uncaught TypeError: Cannot read property 'push' of undefined". I am aware that JavaScript has a built in push and pop method, so I am sure it's not the case. But I am curious as to why it runs in the terminal but not the browser.

Here is the code:

<button onclick = "concertSearch()">Ticket Search</button>
 <script data-main="scripts" src="node_modules/requirejs/require.js"></script>
<p id="search"></p>

<script>
var request = require('request');
var cheerio = require('cheerio');
var URL = require('url-parse');

var START_URL = "https://papertiger.queueapp.com";
var MAX_VISITS = 10;

var pagesVisited = {};
var numPagesVisited = 0;
var pagesToVisit = [];
var url = new URL(START_URL);
var baseURL = url.protocol + "//" + url.hostname;
var artistName;

function concertSearch() {
  var artistName = prompt("Enter the name of the artist you wish to see");

  //var artistName;

  if (artistName == "") {
    document.getElementById("search").innerHTML =
      "You have entered nothing.";
  } else {
    document.getElementById("search").innerHTML =
      "You have entered " + artistName + ".";
    // console.log(pagesToVisit);

    // error occurs here
    pagesToVisit.push(START_URL);
    crawl();
  }


}

function crawl() {
  if (numPagesVisited >= MAX_VISITS) {
    console.log("Reached max limit of pages.");
    return;

  }
  // An error will probably happen here eventually. 
  var nextPage = pagesToVisit.pop();

  if (nextPage in pagesVisited) {
    crawl();
  } else {
    visitPage(nextPage, crawl);
  }
}

function visitPage(url, callback) {
  pagesVisited[url] = true;
  numPagesVisited++;

  console.log("Visiting page: " + url);
  request(url, function(error, response, body) {
    console.log("Status Code: " + response.statusCode);
    if (response.statusCode !== 200) {
      callback();
      return;
    }

    var $ = cheerio.load(body);

    var wordFound = search($, artistName);
    if (wordFound) {
      console.log("Word " + artistName + " found at page " + url);
    } else {
      console.log("Could not find any dates for " + artistName + ".");
      collectInternalLinks($);
      callback();

    }
  })
}

function search($, word) {
  var bodyText = $('html > body').text().toLowerCase();

  return (bodyText.indexOf(word.toLowerCase()) !== -1);
}

function collectInternalLinks($) {
  var relativeLinks = $("a[href^='/']");
  console.log("Found " + relativeLinks.length + " reletive links found.");
  relativeLinks.each(function() {
    pagesToVisit.push(baseURL + $(this).attr('href')); // Another error here eventually
  });
}
</script>

I'm pretty much at a loss and have tried looking to see if I am missing any packages and how to establish arrays properly, I have yielded no results. I'm still new to js so any suggestions or improvements will be helpful. Thanks.

edit: error in the console