How to use *require.js* to load another library inside p5

Hi,

I’d like to use the ‘require.js’ library in p5.js to load another library, say ‘fast-csv’

I’ve done locally:

  1. npm install fast-csv
  2. modify the index.html to include the ‘require’:

<script src=“https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js”></script>

  1. In the ‘sketch.js’ code:

var csv = require(’./node_modules/fast-csv’);

But I’m getting error:

Uncaught Error: Module name “node_modules/fast-csv” has not been loaded yet for context: _. Use require([])
https://requirejs.org/docs/errors.html#notloaded
at makeError (require.min.js:1)
at Object.s [as require] (require.min.js:1)
at requirejs (require.min.js:1)
at sketch.js:20

Could you help? Thanks a lot.

Xuepeng

Hi,

Welcome to the community!

Your question is not really related to p5js but rather to require.js.

As mentioned in the error you got, you should check this link :

and also :