AMD support breaks sites loading widgets.js using a <script> tag


#1

Hi,

It seems that https://platform.twitter.com/widgets.js is trying to define itself as an anonymous AMD module when it finds an AMD-compatible window.define() function.

Doing so is invalid if the script has been loaded using a <script src=https://platform.twitter.com/widgets.js></script> tag, which many sites are doing right now.

For instance this causes require.js to throw an exception, and to fail any subsequent attempt to load an AMD module.

I haven’t noticed this before, is this new ?

Here is the offending code snippet in https://platform.twitter.com/widgets.js:

"function"==typeof define&&define.amd?define(function(){return it})

Here is a reproducing jsfiddle: http://jsfiddle.net/k7t7075x/

The console shows the following error:

Uncaught Error: Mismatched anonymous define() module: function (){return it}
http://requirejs.org/docs/errors.html#mismatch

#2

Nice catch. This broke our site and while we saw it was related to the widget.js we’d not yet figured out why.

Thanks for sharing, I think this will break a lot of sites…


#3

We rolled back the deploy that introduced this problem around 1:15pm PST. If you’re still experiencing the problem, please let us know. Apologies for the inconvenience.


#4

Hi Jake,

Thanks for the quick response.

I confirm that the issue is fixed for us.


#5