• HOME
  • NEWS
  • PORTFOLIO
  • LAB
  • ABOUT
  • CONTACT

Error: Mismatched anonymous define() module: function (require) {

categories : programmation

by Trân on February 17, 2016

error_define

 

I got this error while working on a project using swiper.js :

Error: Mismatched anonymous define() module: function (require) {…

Searching a little on google I found a thread on stack overflow telling that :

requireJS blows up when :

  • You have an anonymous define (“modules that call define() with no string ID“) in its own script tag (I assume actually they mean anywhere in global scope)
  • You have modules that have conflicting names
  • You use loader plugins or anonymous modules but don’t use require.js’s optimizer to bundle them

I had this problem while including bundles built with browserify alongside require.js modules. The solution was to either:

A. load the non-require.js standalone bundles in script tags before require.js is loaded, or

B. load them using require.js (instead of a script tag)

(http://stackoverflow.com/questions/15371918/mismatched-anonymous-define-module)

The problem on the project I’m working on is that I’m writing a standalone widget within a require.js environment with no access at all to any require.js code, this means impossible to load js files in script tags before require.js is loaded and impossible to load them using require.js.

But… wait, why do swiper.js has to support amd if I only need it as a standalone non-require.js bundle ?

Fortunately, at the bottom of the swiper.js plugin you can find these lines :


if (typeof(module) !== 'undefined'){
module.exports = window.Swiper;
} else if (typeof define === 'function' && define.amd) {
define([], function () {
'use strict'; return window.Swiper;
});
}

Well I just simply comment them and it worked !

 

Instagram inspiration » « Instagram inspiration

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

 
 

© fruit du dragon - freelance creative coder

Categories

  • général
  • inspiration
  • lab
  • programmation
  • sites
  • work

Tags

android architecture archives canvas cellules-studio cornelius css culturel demonstrateur design eshop flash fremok html html/css/js hugo IFTTT incandescence Instagram institutionnel ios ipad jeux js krpano luxe media design mobile musée nomoon paper fold photographie requins-marteaux responsive sbam snippet tablette toute-attente tran nn transport typographie ui ultranoir woocommerce wordpress

Stats


Notice: Undefined variable: extra in /home/tigerbal/www/wp-content/plugins/pulsemaps/pm-widget.php on line 47

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org