Uncaught TypeError: undefined is not a function when using require.js

Ray Cheng

I'm new to require.js so I may not be using it correctly, but as far as I know, I can't find what's causing the error.

Structure

index.html
Scripts\
  - jquery-2.1.1.min.js
  - require.js
  \app
    - main.js
  \lib
    - work-requests.js
    - controller-base.js
    - util.js

index.html

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

main.js

requirejs.config({
    baseUrl: 'Scripts/lib',
    paths: {
        jquery: '../jquery-2.1.1.min',
    },
});
requirejs(['jquery', 'util', 'work-requests'], function ($, util, work_requests) {
    $(function () {
    var foo = new work_requests.get_all(); // <-- error "Uncaught TypeError: undefined is not a function
});

work-requests.js

define(['controller-base'], function (controller_base) {
    return function () {
        var that = controller_base('work-requests')

        return that;
    }
});

controller-base.js

define(['jquery'], function ($) {
    return function (controller_name) {
        var that = {};
        that.controller = controller_name;

        that.get_all = function () {
            return $.ajax({
                type: 'get',
                contentType: 'application/json',
                url: _api_root + '/' + that.controller,
            });
        };
        return that;
    };
});

util.js

define({
  foo: function(data){},
});
bowheart

Your require.js setup is completely fine. Did you try changing

var foo = new work_requests.get_all();

to

var foo = new work_requests();
var bar = foo.get_all();

?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Uncaught TypeError: undefined is not a function when using require.js

From Dev

uncaught TypeError: undefined is not a function when using JSON object with name

From Dev

jQuery "Uncaught TypeError: undefined is not a function" when using fadeIn();

From Dev

jQuery "Uncaught TypeError: undefined is not a function" when using fadeIn();

From Dev

Uncaught TypeError: undefined is not a function - typeahead.js

From Dev

Ember.js: Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function - typeahead.js

From Dev

BigVideo.js - Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function while using jQuery

From Dev

Uncaught TypeError:Undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function?

From Dev

Uncaught TypeError: undefined is not a function $

From Dev

Getting a error "Uncaught TypeError: undefined is not a function" when calling a function

From Dev

Uncaught typeError:undefined is not a function while using slide left infullpage.js

From Dev

Uncaught TypeError: is not a function when using window[functionName]

From Dev

Uncaught TypeError: is not a function when using window[functionName]

From Dev

Uncaught TypeError: undefined is not a function when moved same code to another site

From Dev

Uncaught TypeError: undefined is not a function jquery.unobtrusive-ajax.js

From Dev

Backbone.js Models Uncaught TypeError: undefined is not a function

From Dev

Twitter Uncaught TypeError: undefined is not a function

From Dev

Reactjs: Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function - Javascript

From Dev

uncaught typeerror undefined is not a function on .empty()

From Dev

uncaught typeerror undefined is not a function in javascript

Related Related

  1. 1

    Uncaught TypeError: undefined is not a function when using require.js

  2. 2

    uncaught TypeError: undefined is not a function when using JSON object with name

  3. 3

    jQuery "Uncaught TypeError: undefined is not a function" when using fadeIn();

  4. 4

    jQuery "Uncaught TypeError: undefined is not a function" when using fadeIn();

  5. 5

    Uncaught TypeError: undefined is not a function - typeahead.js

  6. 6

    Ember.js: Uncaught TypeError: undefined is not a function

  7. 7

    Uncaught TypeError: undefined is not a function - typeahead.js

  8. 8

    BigVideo.js - Uncaught TypeError: undefined is not a function

  9. 9

    Uncaught TypeError: undefined is not a function while using jQuery

  10. 10

    Uncaught TypeError:Undefined is not a function

  11. 11

    Uncaught TypeError: undefined is not a function

  12. 12

    Uncaught TypeError: undefined is not a function

  13. 13

    Uncaught TypeError: undefined is not a function

  14. 14

    Uncaught TypeError: undefined is not a function

  15. 15

    Uncaught TypeError: undefined is not a function

  16. 16

    Uncaught TypeError: undefined is not a function?

  17. 17

    Uncaught TypeError: undefined is not a function $

  18. 18

    Getting a error "Uncaught TypeError: undefined is not a function" when calling a function

  19. 19

    Uncaught typeError:undefined is not a function while using slide left infullpage.js

  20. 20

    Uncaught TypeError: is not a function when using window[functionName]

  21. 21

    Uncaught TypeError: is not a function when using window[functionName]

  22. 22

    Uncaught TypeError: undefined is not a function when moved same code to another site

  23. 23

    Uncaught TypeError: undefined is not a function jquery.unobtrusive-ajax.js

  24. 24

    Backbone.js Models Uncaught TypeError: undefined is not a function

  25. 25

    Twitter Uncaught TypeError: undefined is not a function

  26. 26

    Reactjs: Uncaught TypeError: undefined is not a function

  27. 27

    Uncaught TypeError: undefined is not a function - Javascript

  28. 28

    uncaught typeerror undefined is not a function on .empty()

  29. 29

    uncaught typeerror undefined is not a function in javascript

HotTag

Archive