0

I am trying to set up folders for require.js and I am just having errors.

Here is my folder structure:

Web folder
--default.html
--[Scripts]
----main.js
----require-cfg.js
----require.js
----[lib]
------jquery1-9.1.js

my require-cfg.js

var require = ({
    baseUrl: 'Scripts',
    paths: {
        jquery: '/lib/jquery-1.9.1'
    }
});

In my main.js:

require(["require-cfg"], function (core) {

});

in my default.html

 <script src="Scripts/require-cfg.js"></script>
  <script src="Scripts/require.js"></script>
  <script src="Scripts/main.js"></script>

I have a function in the main.js that uses jquery syntax. When I run the web app, I am getting the error"

JavaScript runtime error: '$' is undefined

can anyone direct me on what I am doing wrong??

THanks!!

-- I figured out that By default, jQuery registers itself using the global functions "$" and "jQuery", even when used with AMD/RequireJS. If you want to turn off this behavior you have to call noConflict function:Correct way to implement jQuery with require.js

adding the below worked:

define('jquery-private', ['jquery'], function (jq) {
    return jq.noConflict( true );
});
8
  • Should 'require(["require-cfg"]' be 'require(["require-cfg.js"]'? Just a guess. Commented Jan 29, 2014 at 21:48
  • according to this: requirejs.org/docs/start.html, I don't need the .js when requiring it. Commented Jan 29, 2014 at 21:55
  • Maybe try switching <script src="Scripts/require-cfg.js"></script> and <script src="Scripts/require.js"></script> around? Just another guess. Commented Jan 29, 2014 at 22:02
  • Thanks, had tried that too. Commented Jan 29, 2014 at 22:26
  • I'm unfamiliar with require.js. Does it use jQuery? If so, perhaps there is some conflict with the jQuery version it is using and the one you're including. Also, it usually tells you what line of code in which file your error is occuring in your js console. Does it say that? Commented Jan 29, 2014 at 22:43

0

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.