James
James

Reputation: 2860

RequireJS application not recognising my dependencies

I am using RequireJS to load and implement my Javascript modules. I have a require.config.js which looks like this where I define some paths:

'use strict';

window.require([], function() {
    window.require.config({
        baseUrl : site_url + '/wp-content/themes/molecarepetvets/assets/js',
        paths   : {
            urls            : 'routes/routes',
            jquery          : 'vendor/jquery-2.2.0.min.js',
            slideshow       : 'lib/Slideshow',
            formValidation  : 'lib/formValidation',
            requestObject   : 'lib/requestObject',
            toastr          : 'vendor/toastr',
            gmaps           : 'http://maps.google.com/maps/api/js?v=3&sensor=false'
        },
        shim    : {
        },
        deps    : [
            'page'
        ]
    });
});

I then call the 'page' dependency at the bottom which loads my main page Javascript which looks like this:

'use strict';

(function(define) {
    define([
        'jquery',
        'lib/Slideshow',
        'lib/formValidation',
        'urls',
        'requestObject',
        'vendor/toastr',
        'lib/NewsObject',
        'templates/newsArticle',
        'parallax',
        'GoogleMaps'
    ], function(
        $,
        Slideshow,
        formValidation,
        urls,
        requestObject,
        toastr,
        NewsObject,
        newsArticleView,
        parallax,
        GoogleMaps
    ) {
        $(document).ready(function() {
...

Now, when I try and load my application I get the following error:

Uncaught Error: Script error for "", needed by: page

It seems as if some of my modules are not being loaded. I have checked the paths and they are correct. Am I using RequireJS incorrectly? I'm pretty new to it so maybe this is why.

Thanks

Upvotes: 0

Views: 163

Answers (1)

Satej S
Satej S

Reputation: 2156

Posting my comment as an answer after the issue was solved.

While specifying paths, require.js doesn't require the file extension.The current path for JQuery

jquery : 'vendor/jquery-2.2.0.min.js',

is to be replaced with

jquery : 'vendor/jquery-2.2.0.min',

For more information from the documentation

RequireJS also assumes by default that all dependencies are scripts, so it does not expect to see a trailing ".js" suffix on module IDs. RequireJS will automatically add it when translating the module ID to a path.

Upvotes: 1

Related Questions