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 );
});
Community
  • 1
  • 1
alpha
  • 501
  • 2
  • 7
  • 22
  • Should 'require(["require-cfg"]' be 'require(["require-cfg.js"]'? Just a guess. – Jared Price Jan 29 '14 at 21:48
  • according to this: http://requirejs.org/docs/start.html, I don't need the .js when requiring it. – alpha Jan 29 '14 at 21:55
  • Maybe try switching and around? Just another guess. – Jared Price Jan 29 '14 at 22:02
  • Thanks, had tried that too. – alpha Jan 29 '14 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? – Jared Price Jan 29 '14 at 22:43
  • my JS console has no error. It only errors when a jquery selector ($) is used. – alpha Jan 29 '14 at 22:54
  • You're not supposed to use separate – kryger Jan 29 '14 at 23:23
  • When you say "adding the below worked" do you mean your problem is fully resolved now? – Louis Jan 30 '14 at 02:51

0 Answers0