Adding a script through requires->js causes an error: "Mismatched anonymous define() module"

Adding a script through requires->js causes an error: "Mismatched anonymous define() module"

by Lea Cohen -
Number of replies: 2

I'm trying to integrate the select2 library (a jQuery library that adds search functionality to select boxes) in the admin pages of our Moodle.

When I added the JavaScript file using the requires->js function (in a php file in my theme), I got the following error:

Error: Mismatched anonymous define() module
I read in the docs that sometimes RequireJS could cause this error, and so I added it instead via a script tag in a mustache file in my theme.
That solved my problem, but still, I would rather add it the right way. What do I need to do in order for the script to work when added using the requires->js function?
Average of ratings: -
In reply to Lea Cohen

Re: Adding a script through requires->js causes an error: "Mismatched anonymous define() module"

by Lea Cohen -
I found a way to include the script using the requires->js function:
The requires->js function accepts a second parameter - whether to include the script in the header or not. The default is false, so I passed a true value - and that solved the problem!
In reply to Lea Cohen

Re: Adding a script through requires->js causes an error: "Mismatched anonymous define() module"

by Lea Cohen -
I found a way to include the script using the requires->js function:
The requires->js function accepts a second parameter - whether to include the script in the header or not. The default is false, so I passed in a true - and that solved the problem!
Average of ratings: Useful (1)