Question

I am attempting to run r.js against our webapp, but am running into the following error:

Error: Error: The config in mainConfigFile /home/ubuntu/dev/proj/web/insight/js/main.js cannot be used because it cannot be evaluated correctly while running in the optimizer. Try only using a config that is also valid JSON, or do not use mainConfigFile and instead copy the config values needed into a build file or command line arguments given to the optimizer.
Source error from parsing: /home/ubuntu/dev/proj/web/insight/js/main.js: SyntaxError: Duplicate data property in object literal not allowed in strict mode at /home/ubuntu/dev/proj/deploy/r.js:26725:27

My build.js file is:

({
    appDir: "../web/insight",
    baseUrl: "js/",
    mainConfigFile: "../web/insight/js/main.js",
    dir: "insightui-build",
    modules: [
        {
            name: "main"
        }
    ],
    paths: {
        "jquery": "empty:",
        "backbone": "empty:",
        "underscore": "empty:",
        "handlebars": "empty:",
    }
})

My main.js is:

require.config({
paths: {
//  Libraries
// (Look at upgrading: Handlebars, Bootstrap, LESS, Backbone, Underscore
    jquery              : '//code.jquery.com/jquery-1.11.0.min',
    backbone            : '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min',
    underscore          : '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min',
    handlebars          : '//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.rc.1/handlebars.min',
    bootstrap           : '//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min',
    highcharts          : '//cdnjs.cloudflare.com/ajax/libs/highcharts/3.0.2/highcharts',
    leaflet             : '//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.2/leaflet',
    less                : '//cdnjs.cloudflare.com/ajax/libs/less.js/1.3.3/less.min',
    common              : '../shared/js/common',
    config              : 'config',
//  Views
    DefaultView         : 'views/defaultView',
    LoginView           : 'views/LoginView',
    ResetPassView       : 'views/EmailView',
    SetPassView         : 'views/SetPassView',
    SetEmailView        : 'views/SetEmailView',
    ResetPassView       : 'views/ResetPassView',
    HomeView            : 'views/HomeView',
    FleetView           : 'views/FleetView',
    FleetSitesView      : 'views/FleetSitesView',
    FleetOpsView        : 'views/FleetOpsView',
    FleetInstsView      : 'views/FleetInstsView',
    InstProfileView     : 'views/InstProfileView',
    InviteView          : 'views/InviteView',
    OpProfileView       : 'views/OpProfileView',
    SiteProfileView     : 'views/SiteProfileView',
    SupportView         : 'views/SupportView',
    TestsView           : 'views/TestsView',
    TestDetailView      : 'views/TestDetailView',
    UsersView           : 'views/UsersView',
    UserSettingsView    : 'views/settings/UserSettingsView',
//  Shared Subviews
    ActivityFeedView    : 'views/shared/ActivityFeedView',
    AllNotifView        : 'views/shared/AllNotifView',
    FooterView          : 'views/shared/FooterView',
    HeaderView          : 'views/shared/HeaderView',
    NotifListView       : 'views/shared/NotifListView',
    ProfileChartView    : 'views/shared/ProfileChartView',
//  Settings Subviews
    AddInstView         : 'views/settings/AddInstView',
    AddOpView           : 'views/settings/AddOpView', 
    AddUserView         : 'views/settings/AddUserView',
    EditInstView        : 'views/settings/EditInstView',
    EditSiteView        : 'views/settings/EditSiteView',
    EditUserView        : 'views/settings/EditUserView',
//  Models
    MultiModel          : '../shared/js/models/MultiModel',
    NotifModel          : '../shared/js/models/NotifModel',
    InstModel           : 'models/InstModel',
    OpModel             : 'models/OpModel',
    SiteModel           : 'models/SiteModel',
    TestModel           : 'models/TestModel',
    UserModel           : 'models/UserModel',
//  Collections
    NotifCollection     : '../shared/js/collections/NotifCollection',
    InstsCollection     : 'collections/InstsCollection',
    InviteCollection    : 'collections/InviteCollection',
    OpsCollection       : 'collections/OpsCollection',
    SitesCollection     : 'collections/SitesCollection',
    TestsCollection     : 'collections/TestsCollection',
    UsersCollection     : 'collections/UsersCollection',
//  Templates
    templates           : '../templates',
},

shim: {
    underscore: {
      exports: '_'
    },
    backbone: {
        deps: ['underscore', 'jquery'],
        exports: 'Backbone'
    },
    handlebars: {
        exports: 'Handlebars'
    },
    bootstrap: {
      deps: ['jquery'],
      exports: '$'
    },
    highcharts: {
        deps: ['jquery'],
        exports: 'Highcharts'
    },
    leaflet: {
        exports: 'L'
    }
}
});

require([ // Load our app module and pass it to our definition function
    'app',
    ], function(App){
    // The "app" dependency is passed in as "App"
    App.initialize();
});

I've exhausted searching google. I thought I could just plug in main.js as the mainConfigFile and it would take off, but apparently I have some other issue(s). Thanks in advance for any help.

Était-ce utile?

La solution

ResetPassView appears twice in your paths. That's an illegal JavaScript object. That's your error.

The error message: SyntaxError: Duplicate data property in object literal not allowed in strict mode was a gigantic clue that this was the problem. Cut and paste your config into an empty .js file, have node parse it, and bingo:

/tmp/foo.js:23
    ResetPassView       : 'views/ResetPassView',
    ^^^^^^^^^^^^^
SyntaxError: Duplicate data property in object literal not allowed in strict mode
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top