简体   繁体   English

使用Backbone.js和Require.js的IE8网站错误

[英]Errors in IE8 for site using Backbone.js w/ Require.js

I'm getting the following errors coming back in IE8: 我在IE8中遇到以下错误:

Message: Object expected Line: 27 Char: 1 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/jquery.backgroundSize.js 消息:预期的对象行:27字符:1代码:0 URI: http//cdn.example.com/images/example4/js/libs/jquery.backgroundSize.js

Message: '$.fn' is null or not an object Line: 8 Char: 1 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/jquery.waitUntilExists.js 消息:'$。fn'为空或不是对象行:8字符:1代码:0 URI: http : //cdn.example.com/images/example4/js/libs/jquery.waitUntilExists.js

Message: 'fn' is null or not an object Line: 62 Char: 73 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/jquery.nicescroll.js 消息:'fn'为空或不是对象行:62字符:73代码:0 URI: http : //cdn.example.com/images/example4/js/libs/jquery.nicescroll.js

Message: Object expected Line: 34 Char: 231 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/backbone.js 消息:预期的对象行:34字符:231代码:0 URI: http//cdn.example.com/images/example4/js/libs/backbone.js

Message: 'Vent' is null or not an object Line: 19 Char: 3 Code: 0 URI: http://cdn.example.com/images/example4/js/models/auth.js 消息:“通风口”为空或不是对象行:19字符:3代码:0 URI: http//cdn.example.com/images/example4/js/models/auth.js

Our site is a SPA built with Backbone.js and Require.js for dependency management. 我们的网站是使用Backbone.js和Require.js构建的SPA,用于依赖性管理。 This problem only shows up on IE8 (and possibly earlier versions). 此问题仅在IE8(可能还有更早的版本)上显示。 Each of these files, with the exception of the last which is caused because 'Vent' extends Backbone.Event, are all created as shims for Backbone.js in our Require.js config file. 这些文件中的每一个,除了最后一个是由于“通风孔”扩展了Backbone.Event引起的,都在Require.js配置文件中创建为Backbone.js的垫片。

Require.js config: Require.js配置:

requirejs.config({
    baseUrl: 'http://cdn.staging.example.com/images/example4/js',
    paths: {
        underscore: './libs/underscore',
        jquery: './libs/jquery',
        backbone: './libs/backbone',
        example: './libs/example',
        blockui: './libs/jquery.blockUI',
        backgroundsize: './libs/jquery.backgroundSize',
        nicescroll: './libs/jquery.nicescroll',
        waituntilexists: './libs/jquery.waitUntilExists',
        swfobject: './libs/swfobject',
        spinner: './libs/jquery.spinner'
    },
    //Create shims for Backbone
    shim: {
        'backgroundsize': {
            deps: [ 'jquery'],
            exports: 'backgroundsize'
        },
        'nicescroll': {
            deps: ['jquery'],
            exports: 'nicescroll'
        },
        'waituntilexists': {
            deps: ['jquery'],
            exports: 'waituntilexists'
        },
        'spinner': {
            deps: ['jquery'],
            exports: 'spinner'
        },
        'backbone': {
            deps: [ 'underscore', 'jquery','blockui','backgroundsize','nicescroll', 'waituntilexists', 'swfobject', 'spinner'],
            exports: 'Backbone'
        }
    }
});

requirejs(['app'],
    function(App){
        App.initialize();
    });

Any suggestions as what would be causing this, we're using Backbone.js 0.9.2 and Require.js 2.0.6. 任何可能导致此问题的建议,我们正在使用Backbone.js 0.9.2和Require.js 2.0.6。

IE has some issues with shims as you can read here http://requirejs.org/docs/errors.html#nodefine IE浏览器存在一些垫片问题,您可以在此处阅读http://requirejs.org/docs/errors.html#nodefine

As far as I understand from http://requirejs.org/docs/api.html#config-shim 据我对http://requirejs.org/docs/api.html#config-shim的了解

Only use other "shim" modules as dependencies for shimmed scripts, or AMD libraries that have no dependencies and call define() after they also create a global (like jQuery or lodash). 仅将其他“填充程序”模块用作填充脚本的依赖性,或者将不具有依赖性的AMD库也创建全局变量(如jQuery或lodash)后调用define()。 Otherwise, if you use an AMD module as a dependency for a shim config module, after a build, that AMD module may not be evaluated until after the shimmed code in the build executes, and an error will occur. 否则,如果您将AMD模块用作垫片配置模块的依赖项,则在构建之后,可能要等到构建中的填充代码执行后,才能评估该AMD模块,否则会发生错误。 The ultimate fix is to upgrade all the shimmed code to have optional AMD define() calls. 最终的解决方法是将所有填充的代码升级为具有可选的AMD define()调用。

There could be an issue with having jquery as a dependency of a shim or jquery was not loaded so it couldnt set it's global. 将jquery作为填充程序的依赖项可能存在问题,或者jquery没有加载,因此无法将其设置为全局。

Try adding backbone to your main require like this: 尝试将主干添加到您的主要需求中,如下所示:

    requirejs(['app', 'backbone'], function(App){ App.initialize(); });

Also, try to use r.js to generate one concatenated file (make sure you turn off optimization) and you can see the order in which require is loading scripts. 另外,尝试使用r.js生成一个串联文件(确保关闭优化),然后可以看到require加载脚本的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM