0

I'm trying to use a JS library (this) which makes use of the require function. To use it, I understand I have some options, as elaborated on here. So I go with requireJS and I link to it and the library I want to use as such in my html file.

<script src="requirejs/reqjs.js"></script>
<script src="LIBRARY_I_WANT_TO_USE/index.js"></script>

the first line of index.js looks like this

var foo = require('PATH')

For that line, the console outputs this error:

Uncaught Error: Module name "PATH" has not been loaded yet for context: _. Use require([])

So I find this at requirejs.org:

This occurs when there is a require('name') call, but the 'name' module has not been loaded yet.

It goes on to suggest ways to resolve the problem. But I hesitate to start modifying the code of the library I just downloaded. Now my question is,

Is the library I downloaded bugged, or am I doing something wrong?

Community
  • 1
  • 1
liksnfi
  • 13
  • 3

1 Answers1

0

That library is written using CommonJS modules, not AMD modules (which is what RequireJS implements).

You need to use browserify to bundle it into a single file that can load in the browser.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964