0

I am configuring RequireJS like so:

require.config({
    paths: {
        jquery: 'jquery-1.8.3.min',
        knockout: 'knockout-2.2.0',
        komapping: 'knockout.mapping-latest',
        token: 'jquery.tokeninput'
    },
    shim: {
        jQuery: {
            exports: 'jQuery'
        }
    }
});

When I look at the actual requests with Fiddler, I see it is looking for jquery.js and nothing works properly. If I add a file jquery.js to my project, it works.

Why is it not using the version-specific library as I have specified? The reason I want the specific version is because I am using NuGet to manage my packages (Visual Studio .Net obviously, and this is an ASP.Net MVC application) and I want to avoid needing to remember to copy the file every time JQuery is updated.

1
  • You should add an example of one require/define calling jQuery. Commented Jan 9, 2013 at 16:57

1 Answer 1

2

First of all, jQuery is compatible with AMD. You don't need shim to use it.

Next, jQuery !== jquery, you should make sure your naming is consistent so it load the correct path configuration.

Also, make sure that require.config is run before you make any other calls as this could lead to require not using the path you configured upper.

Sign up to request clarification or add additional context in comments.

3 Comments

You're right. I removed the shim completely. As for the jQuery/jquery, I have no idea where I got that from, but I vaguely recall when I originally added RequireJS to the project (before the Christmas/New Year's break), I needed to use 'jQuery' to get things to work at all. It was when I started to clean up the code today to make the project maintainable that things started to break. I wish I could find where I got the 'jQuery' idea from so I could look again and figure out what has changed and why that was suggested.
On further testing, while that change doesn't break anything, it doesn't fix the issue either. It did on the first page load after making the change, but after refreshing the page it went right back to looking for jquery.js. I've also seen other inconsistencies, such as the name of a required js file changing from one request to the next (e.g. jquery-tokeninput.js on one request, token.js on the next) with no code changes, and issues with 401 unauthorized one moment, and 200 success the next for static content with allowed users="*". I'm going to investigate with a different setup tomorrow.
The last comment (require.config before any other calls) set me on the right path. stackoverflow.com/questions/9830290/… clued me in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.