0

So I am working on my first project and I cant seem to load a scraper js file since the html says that 'require' is not defined.

I have heard about requirejs, but its a bit hard for me to understand.

So this is my javascript file:

const malScraper = require('mal-scraper');

// more code ...

document.getElementById('output').innerHTML = currentSeason;

and then in index.html i want it to load the scraped results in a paragraph like this

<p id='output'>Here: </p>
Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29

1 Answers1

0

Require is not implemented in the browser natively, you'll need a polyfill (it's a dependency that reproduces its behavior).

It's the purpose of Require.js, Browserify, and other packages.

Here's a sample code with Browserify:

<html>
<head>
</head>
<body>

   <!-- Your HTML Stuff -->

    <script type="text/javascript" src="./browserify.js"></script>
    <script type="text/javascript">
    const malscraper = require('./mal-scraper'); // The path to the dependency

    malscraper(): // And now you can use it
</script>
</body>
</html>
l-portet
  • 636
  • 7
  • 14