RequireJS Mismatched anonymous define error caused by Drupal?

3.3k Views Asked by At

I've had a require.js app running on my drupal site for a few months now. To my knowledge, nothing has changed in the app's code, but suddenly yesterday I started getting the following error:

Uncaught Error: Mismatched anonymous define() module:

Interestingly, I got this same error even when my main.js file only included the following:

require.config({});
require([''], function() {
});

But, when I left main.js completely empty, I got the following error:

Uncaught Error: Script error for: piwik

Piwik is the first js file included at the head of the document.

I checked the Require.js documentation and found that this can be caused by loading require modules outside of the Require.js API. To test if this was the case I ran my app outside of the Drupal environment -- instead of loading the in a Drupal template I am now loading it through an external html file with the same markup as the Drupal template file. In that setup I don't receive the error and the app loads as expected.

So my question then is, are there any known conflicts with Drupal core javascript files and require.js? The only thing I can imagine causing a problem is that jquery (which is included in the document head) does a check to see if define is a function and if it is defines jquery as a module... but jquery loads before I include the require.js script.

I don't have any other scripts containing "define", "require" or "module" on the page.

I'm using the most current version of Require (2.1.8) and the latest Drupal version (7.2.3)

1

There are 1 best solutions below

0
On

Alright -- I've solved the above problem. Kind of.

To debug the problem, I used "enforceDefine: false" in my require.config. Immediately I got an error telling me that one of my required dependencies was missing a define function. I checked and that was indeed the case (seems to have been caused by a new git commit). I still get the mismatch error, but at least the app loads.

FURTHER UPDATE:

Ended up being caused by piwik's use of 'define'. Apparently this is fixed in the upcoming Piwik version.