Hi! I have been searching for information to use a JS node_module that needs to be required in my plugin. I have followed the instructions for an external javascript/jquery library from https://docs.moodle.org/dev/Javascript_Modules and from https://docs.moodle.org/dev/Guide_to_adding_third_party_jQuery_for_AMD, but it didn't work.
I came to the conclusion that I need to use AMD, so I created a file named config.js inside the folder /amd/src:
I want to use the library sentiment (https://www.npmjs.com/package/sentiment). I placed this library in a /js folder and also I tried to add it to the /amd/src folder and use the build path, as the example above.
Then, I created a file at /amd folder named sentimentM.js:
define(['local_analysentiment/config', 'sentimentM'], function(unused,SM) { return SM; });
And finally, a file named analysentiment.js at /amd/src:
I use grunt to compile it and in my index.php I add the following line:
- require.js:1961 GET http://localhost/turisme/lib/requirejs.php/-1/sentimentM.js net::ERR_ABORTED 404
- require.js:168 Uncaught Error: Script error for "sentimentM", needed by: local_analysentiment/sentimentM http://requirejs.org/docs/errors.html#scripterror at makeError (require.js:168:17) at HTMLScriptElement.onScriptError (require.js:1738:36)
I tried too many things: adding also to my PHP file the other js files (although they seem to compile alone), using other requirements or definitions, pray... At some point, the error requires also "async", and I could manage it; but then the error was that I need "fs" and I have no idea of what to do! And also I don't think this is a solution :C.
Any clue of what to do? Any functional examples?