需要优化器和mainConfigFile错误

时间:2014-04-30 15:58:58

标签: javascript requirejs require requirejs-optimizer

我正在尝试针对我们的webapp运行r.js,但遇到以下错误:

  

错误:错误:无法使用mainConfigFile /home/ubuntu/dev/proj/web/insight/js/main.js中的配置,因为在优化程序中运行时无法正确评估它。尝试仅使用也是有效JSON的配置,或者不使用mainConfigFile,而是将所需的配置值复制到为优化器提供的构建文件或命令行参数中。
  解析时出现源错误:/home/ubuntu/dev/proj/web/insight/js/main.js:SyntaxError:严格模式下不允许对象文字中的重复数据属性       at /home/ubuntu/dev/proj/deploy/r.js:26725:27

我的build.js文件是:

({
    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:",
    }
})

我的main.js是:

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();
});

我已经筋疲力尽地搜索谷歌了。我以为我可以插入main.js作为mainConfigFile它会起飞,但显然我还有其他一些问题。提前感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

ResetPassViewpaths中出现两次。这是一个非法的JavaScript对象。这是你的错误。

错误消息:SyntaxError: Duplicate data property in object literal not allowed in strict mode巨大的线索,这就是问题所在。将您的配置剪切并粘贴到一个空的.js文件中,让node解析它,并使用宾果游戏:

/tmp/foo.js:23
    ResetPassView       : 'views/ResetPassView',
    ^^^^^^^^^^^^^
SyntaxError: Duplicate data property in object literal not allowed in strict mode