iframe-resizer icon indicating copy to clipboard operation
iframe-resizer copied to clipboard

`Error: Mismatched anonymous define() module` on the BBC website

Open YoranBrondsema opened this issue 9 years ago • 8 comments

Hi,

We're trying to use iframe-resizer on an embed on the BBC website. However, it fails with the following errors:

Uncaught ReferenceError: iFrameResize is not defined
Uncaught Error: Mismatched anonymous define() module: function p(){function t(e,n){if(!e.tagName)throw new TypeError("Object is not a valid DOM element");if("IFRAME"!==e.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+e.tagName+">.");m.call(e,n)}return n(),e(window,"message",a),e(window,"resize",w),function(e,n){switch(typeof n){case"undefined":case"string":Array.prototype.forEach.call(document.querySelectorAll(n||"iframe"),function(n){t(n,e)});break;case"object":t(n,e);break;default:throw new TypeError("Unexpected data type ("+typeof n+").")}}}

This error is documented here: http://requirejs.org/docs/errors.html#mismatch.

If you manually code a script tag in HTML to load a script with an anonymous define() call, this error can occur.

I am solving it now by patching the iframeResizer.js code to always export a global, even if the page uses RequireJS modules. I thought it's something you should be aware of though.

YoranBrondsema avatar Feb 19 '16 13:02 YoranBrondsema

That's strange, as the tests load it in by require and don't have this issue.

davidjbradshaw avatar Feb 23 '16 13:02 davidjbradshaw

Hi, I am having a similar issue. My code is being loaded onto a number of different websites some of which may or may not use RequireJS (or similar). Unfortunatly the global iFrameResize (in the window object) not set under certain conditions. It would be great if the iFrameResize object was always set in the global.

ace007 avatar Mar 10 '16 17:03 ace007

I need to see a simple test case to look into this.

https://github.com/davidjbradshaw/iframe-resizer/blob/master/CONTRIBUTING.md

davidjbradshaw avatar Apr 27 '16 14:04 davidjbradshaw

My code has no dependences and makes no assumptions about external frameworks or support libraries. It is given to clients to put on their web pages to work within their environment. Because of this it would be good if the global window.iFrameResize object was always set regardless of any other framework. Unfortunately the web page that was giving me problems have been changed (it's a clients not mine) and doesn't give any problems now. As I don't have the code for the original page I can't give a test case. I would have thought a simple option would be a try/catch around the createJQueryPublicMethod, define and module detection to catch the error whilst always setting the global.

ace007 avatar Apr 28 '16 11:04 ace007

OK your the second person to suggest that the jQuery bit might cause an issue during load, if the page does something weird to make jQuery late load.

I'm going to add a check for $.fn before trying to add to it.

davidjbradshaw avatar Jun 13 '16 12:06 davidjbradshaw

this still happens for me if I load iframe-resize after current version of requirejs

moonray avatar Oct 24 '18 17:10 moonray

What error do you get?

davidjbradshaw avatar Oct 24 '18 22:10 davidjbradshaw

I get this error on https://www.cambridgechorale.org.uk/concerts/the-passing-of-the-year-cambridge because the https://helmtickets.com IFRAME widget is using the plug-in and the site uses require.js.

robtree avatar Jun 09 '19 16:06 robtree

@YoranBrondsema or anyone else who understood what was met

I am solving it now by patching the iframeResizer.js code to always export a global, even if the page uses RequireJS modules. I thought it's something you should be aware of though.

If anyone else gets stuck here, I just replaced define with require and it worked.

  if (typeof define === 'function' && define.amd) {
    require([], factory) //--> this is the line
  } else if (typeof module === 'object' && typeof module.exports === 'object') {
    // Node for browserfy
    module.exports = factory()
  }

trackmyapp avatar Oct 10 '22 15:10 trackmyapp