Skip to content

rails-ujs/activestorage causes require.js error "Mismatched anonymous define() modules" #39713

Closed
@coldnebo

Description

@coldnebo

Steps to reproduce

<%= javascript_include_tag "requirejs" %>
<%= javascript_include_tag "application" %>

Expected behavior

page should load

Actual behavior

Console error in Firefox dev tools:

Error: Mismatched anonymous define() module: [object Object]
http://requirejs.org/docs/errors.html#mismatch require-2.3.5.js:177:17
    makeError https://www-dev1.mathworks.com/licensecenter/MW/RequireJS/require-2.3.5.js:177
    intakeDefines https://www-dev1.mathworks.com/licensecenter/MW/RequireJS/require-2.3.5.js:1269
    localRequire https://www-dev1.mathworks.com/licensecenter/MW/RequireJS/require-2.3.5.js:1460
Error: Mismatched anonymous define() module: function(exports) {
  "use strict";
  function createCommonjsModule(fn, module) {
    return module = {
      exports: {}
    }, fn(module, module.exports), module.exports;
  }
  var sparkMd5 = createCommonjsModule(function(module, exports) {
    (function(factory) {
      {
        module.exports = factory();
      }
    })(function(undefined) {
      var hex_chr = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ];
      function md5cycle(x, k) {
        var a = x[0], b = x[1], c = x[2], d = x[3];
        a += (b & c | ~b & d) + k[0] - 680876936 | 0;
        a = (a << 7 | a >>> 25) + b | 0;
        d += (a & b | ~a & c) + k[1] - 389564586 | 0;
        d = (d << 12 | d >>> 20) + a | 0;
        c += (d & a | ~d & b) + k[2] + 606105819 | 0;
        c = (c << 17 | c >>> 15) + d | 0;
        b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
        b = (b << 22 | b >>> 10) + c | 0;
        a += (b & c | ~b & d) + k[…

System configuration

Rails version: 5.2.4.3

Ruby version: 2.6.6

Source causing the issue

from the gems directory

$ find . -type f -ipath "*5.2.4.3*" | xargs grep -A 2 "define.amd"
./actionview-5.2.4.3/lib/assets/compiled/rails-ujs.js:  } else if (typeof define === "function" && define.amd) {
./actionview-5.2.4.3/lib/assets/compiled/rails-ujs.js-    define(Rails);
./actionview-5.2.4.3/lib/assets/compiled/rails-ujs.js-  }
--
./activestorage-5.2.4.3/app/assets/javascripts/activestorage.js:  typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define([ "exports" ], factory) : factory(global.ActiveStorage = {});
./activestorage-5.2.4.3/app/assets/javascripts/activestorage.js-})(this, function(exports) {
./activestorage-5.2.4.3/app/assets/javascripts/activestorage.js-  "use strict";
--
./actioncable-5.2.4.3/lib/assets/compiled/action_cable.js:  } else if (typeof define === "function" && define.amd) {
./actioncable-5.2.4.3/lib/assets/compiled/action_cable.js-    define(ActionCable);
./actioncable-5.2.4.3/lib/assets/compiled/action_cable.js-  }

These are all anonymous defines. See https://requirejs.org/docs/errors.html#mismatch

Attempted Workaround

rails-ujs appears in the manifest, but so do other things that requirejs, so, requirejs should come before application.

Trying to put require after application might work, but would involve taking other defines out of assets.

I'm not sure what the current thinking is. Looked at requirejs-rails, but open issue there: jwhitley/requirejs-rails#268

I think maybe asset pipeline isn't compatible with requirejs, but then why attempt to support amd defines in rails-ujs? Is there a requirejs config I'm missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions