Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
coldnebo opened this issue Jun 24, 2020 · 1 comment
Labels

Comments

@coldnebo
Copy link
Contributor

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?

@rails-bot
Copy link

rails-bot bot commented Sep 22, 2020

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Sep 22, 2020
@rails-bot rails-bot bot closed this as completed Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant