I am working on an application that uses requirejs and loads underscore with it but also loads underscore as a node_module using a script. Since we needed functionality found in lodash I decided to replace underscore with lodash in requirejs and in script tags. While it was working with underscore when I replaced it with lodash I started getting:
Uncaught Error: Mismatched anonymous define() module: function () {
return _;
}
http://requirejs.org/docs/errors.html#mismatch
I am using the following npm versions:
requirejs "2.1.5"
underscore: "1.3.3"
and I want to install
lodash: "4.5.1"
Here is the requirejs config part that I can post:
require.config({
waitSeconds: 15,
"paths": {
underscore: "../../node_modules/lodash/lodash",
jquery: "lib/jquery-1.7.2",
Backbone: "lib/backbone",
moment: "lib/moment-2.0.0",
text: "lib/text",
alertify: "lib/alertify",
datatables: "lib/jquery.dataTables",
datatablesjqueryui: "lib/dataTables.jqueryui"
},
"shim": {
XYZ: ["underscore","jquery", ...]
...
}
});
The above is part of a concat file that contains also
node_modules/requirejs/require.js
before itI also have another concat after it with the rest of the libraries that include lodash in it.
Both concat files are added using a
<script>
tag.In the last concat I have a lot of files that do
var _ = require("underscore");
or have it in their define dependencies like define(["underscore"],function(_) { ... });
so hopefully i won't need to change anything there
I would appreciate if someone can explain why this happens only with lodash and not underscore. And if there is a solution that will let me add lodash in the concatenated file after it was imported/required through requirejs.
Per possible duplicate: I made sure there are no anonymous defines in the application and I made sure there is no underscore loaded anywhere. So the question is different because I only changed the path from underscore to dash library for the whole application and nothing else.
Thanks!