-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RequireJS 'Mismatched anonymous define() module' #238
Comments
Hi @julianshapiro, Please can you reopen this issue? There is a problem with this implementation for a few reasons:
The issue that I believe @Razinsky was having is that the r.js optimiser will skip naming modules if there is more than one define call. The case with Velocity is that there are two, one with the jquery dependency and one without. If there was only one define, e.g. The solution I propose is to remove the shim option and have a separate build file with that define call, and also remove the name from the define call. This means that the number of define calls will be reduced to one, which will fix the issue. Also see requirejs/r.js#716 for the issue I've raised on r.js with multiple define calls. |
Hey @TheFuzzball, Urgent request, if I may: Can you change the shimmed Velocity loading code to this: /* CommonJS module. */
if (typeof module === "object" && typeof module.exports === "object") {
module.exports = factory(window.Velocity ? window.jQuery : require("jquery"));
/* AMD module. */
} else if (typeof define === "function" && define.amd) {
define(window.Velocity ? factory : [ "jquery" ], window.Velocity ? undefined : factory);
/* Browser globals. */
} else {
factory(window.jQuery);
} And tell me if that fixes everything? |
Hi Julian, That was the first thing that I tried, unfortunately any dynamism isn't going to work here. r.js parses each file for define calls, which define both the module and the dependencies of that module. It then builds up a single file with all of your code using the names of these modules also ensuring the dependencies that they have declared are also in the file. The problem is that r.js is evaluating the define call, and if it hits anything other than I think this issue comes down to having optional dependencies in a single build, where clearly having two define calls implies that there should be two variants of this module. I suggest working with a build tool to generate distribution files, one variant that isn't dependent on jquery (and has a bundled shim), and another that is. That's the cleanest solution that I can see. |
I was hoping that wasn't the case. On a side note, I dislike changing my code for the behavior of one optimizer. But I presume rjs is fairly popular. I only want one build of Velocity. I'm cool with changing my build process, though, such that I actually reposition the shim inside the module's IIFE. Stay tuned. Thank you, as always. |
Okay, I'll create a test build with the four options (w & w/o jQuery, built w/ r.js and unbuild), I'll create a pull request in a bit to fix this once and for all. You shouldn't have to change the way you structure your project for this. |
Hi Julian, I've made a pull request for a change that allows those four (most common) RequireJS use cases. I've also updated the documentation to be more accurate. If you need anything else from me -- the documentation will probably need fixing up, it's late here so there will probably be typos -- let me know. Velocity with RequireJSVelocity presently has two builds,
Both velocity builds can be used with requirejs and r.js simply by including it in your project and requiring it. If you're using As is usual for jQuery plugins, If you want to use the Velocity utility function in your jQuery project, simply require velocity as a dependency, and the value for that dependency will be the utility function. If you're not using jQuery then you will be using the utility function in all cases. If you're using a custom build of jQuery, please ensure that the |
When you say "and that it is required before Velocity" do you in fact mean "make sure jQuery is shimmed as a dependency in your requirejs configuration"? Because, as far as I'm aware, there's no way to require one library "before" another since requirejs loads scripts asynchronously. |
That is what I meant, but I didn't include it in my example. (Updated now.) |
…ub repo. Should update bower.json when the following tickets show progress: julianshapiro/velocity#264 julianshapiro/velocity#238
I've done an overhaul of the module loading code and I've officially dropped the |
This should be fixed now. Please update to the latest version of Velocity and get back to me. |
Fixes CommonJS module loading. Closes #232. Closes #238. Allow animating with the raw utility function (Velocity) instead of its property (Velocity.animate), e.g. $.Velocity(element, propertiesMap, options); Copy over _cacheValues option for the UI pack. Closes #239. Reverts Velocity.mock to original (asynchronous) behavior. Closes #237. Fixes IE7 error throwing in UI pack. Closes #246.
Hi @julianshapiro, awesome work on Velocity.js!
I got this error:
while trying to include Velocity into my compiled r.js (using grunt-contrib-requirejs). After looking for issue #232 I made some tests to find out that I needed to describe the module name in the define call. So instead of
I would have to add 'Velocity' to make it work on my side once compiled:The text was updated successfully, but these errors were encountered: