scottmrogowski
scottmrogowski

Reputation: 2133

Basic require.js example

index.html

<html>

    <head>
        <script data-main="main" src="http://requirejs.org/docs/release/2.1.8/minified/require.js"></script>
    </head>

    <body></body>

</html>

main.js

requirejs.config({
    paths: {
        jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min'
    }
});

define(['jquery'], function ($) {
    console.log($);
});

Why does console.log give me undefined?

Upvotes: 0

Views: 462

Answers (1)

kamituel
kamituel

Reputation: 35970

AMD support (which is required by RequireJS) has been added to jQuery 1.7, and you are trying to use jQuery 1.6.

In order to use jQuery 1.6 with RequireJS, try adding shim configuration:

requirejs.config({
  paths: {
    jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min'
  },
  shim: {
    jquery: {exports: '$'}
  }
});

Alternatively, you can use newer version of jQuery (at least 1.7):

requirejs.config({
  paths: {
    jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min'
  }
});

Upvotes: 2

Related Questions