【问题标题】:Getting errors in IE8 and IE9 only not in other browsers仅在 IE8 和 IE9 中出现错误,在其他浏览器中没有
【发布时间】:2014-08-05 16:16:23
【问题描述】:

我正在开发一个使用大量 js 库并且主要使用 Express JS 的应用程序。 所有代码都可以在 Firefox 和 Chrome 上正常运行。但我在 IE8 和 IE9 中遇到错误。

SCRIPT5022: fromText eval for hbs!notification/templates/dropDown failed: SyntaxError: Syntax error in regular expression
http://requirejs.org/docs/errors.html#fromtexteval 
require.js, line 138 character 9

SCRIPT5022: fromText eval for hbs!notification/templates/dropDownItem failed: SyntaxError: Syntax error in regular expression
http://requirejs.org/docs/errors.html#fromtexteval 
require.js, line 138 character 9

SCRIPT5022: fromText eval for hbs!layouts/admin/templates/teamManagement failed: SyntaxError: Syntax error in regular expression
http://requirejs.org/docs/errors.html#fromtexteval 
require.js, line 138 character 9

SCRIPT5022: fromText eval for hbs!layouts/admin/alarms/templates/projectAlarms failed: SyntaxError: Syntax error in regular expression
http://requirejs.org/docs/errors.html#fromtexteval 
require.js, line 138 character 9

SCRIPT5022: fromText eval for hbs!admin/templates/navigation failed: SyntaxError: Syntax error in regular expression
http://requirejs.org/docs/errors.html#fromtexteval 
require.js, line 138 character 9

SCRIPT5022: fromText eval for hbs!layouts/admin/templates/base failed: SyntaxError: Syntax error in regular expression
http://requirejs.org/docs/errors.html#fromtexteval 
require.js, line 138 character 9

这些错误只出现在 IE8 和 IE9 中。

这是我的 config.js

require.config({
  paths: {
    // Require plugins
    'text': 'vendor/requirejs-text/text',
    'css': 'vendor/css/css',
    'hbs': 'vendor/require-handlebars-plugin/hbs',
    'Handlebars': 'vendor/require-handlebars-plugin/Handlebars',
    'i18nprecompile': 'vendor/require-handlebars-plugin/i18nprecompile',
    'json2': 'vendor/require-handlebars-plugin/json2',

    // Libraries
    'es5shim': 'vendor/es5-shim/es5-shim',
    'underscore': 'vendor/underscore/underscore',
    'jquery': 'vendor/jquery/jquery',
    'jquery.DatePicker': 'vendor/datepicker/datepicker',
    'jquery.mousewheel': 'vendor/jquery-mousewheel/jquery.mousewheel',
    'backbone': 'vendor/backbone/backbone',
    'backbone.virtualCollection': 'vendor/backbone-virtual-collection/backbone.virtual-collection',
    'backbone.marionette': 'vendor/backbone.marionette/backbone.marionette',
    'backbone.marionette.handlebars': 'vendor/backbone.marionette.handlebars/backbone.marionette.handlebars',
    'leaflet': 'vendor/leaflet/leaflet-src',
    'highcharts': 'vendor/highcharts/highcharts.src',
    'paper': 'vendor/paper/paper',
    'handsontable': 'vendor/handsontable/jquery.handsontable',
    'walltime': 'vendor/walltime-js/walltime',
    'walltime-data': 'vendor/walltime-js/walltime-data'
  },
  shim: {
    'underscore': {
      exports: '_'
    },
    'jquery.DatePicker': {
      deps: ['jquery']
    },
    'backbone': {
      deps: ['underscore', 'jquery'],
      exports: 'Backbone'
    },
    'backbone.marionette': {
      deps: ['backbone'],
      exports: 'Marionette'
    },
    'backbone.virtualCollection': {
      deps: ['backbone', 'underscore']
    },
    'leaflet': {
      exports: 'L'
    },
    'highcharts': {
      deps: ['jquery'],
      exports: 'Highcharts'
    },
    'walltime': {
      deps: ['walltime-data']
    }
  },
  hbs: {
    i18nDirectory: 'i18n/',
    disableI18n: false,       // This disables the i18n helper and
                              // doesn't require the json i18n files (e.g. en_us.json)
                              // (false by default)

    disableHelpers: true,     // When true, won't look for and try to automatically load
                              // helpers (false by default)

    helperPathCallback:       // Callback to determine the path to look for helpers
      function (name) {       // ('/template/helpers/'+name by default)
        return 'cs!' + name;
      },

    compileOptions: {}        // options object which is passed to Handlebars compiler
  }
});

请帮帮我!

----- 更新 -----

我将此作为问题发布在 Github 上,用于 requirejs 存储库。
你可以找到它here
根据评论,IE9 中的 eval 似乎有问题。
我还尝试将eval("("+text+")") 放在here 中,但仍然没有成功。

谁能告诉我如何让这个 eval 东西在 IE9 中工作。

谢谢

【问题讨论】:

标签: javascript internet-explorer requirejs


【解决方案1】:

这是我的问题,很可能是你的问题:

//IE with conditional comments on cannot handle the
//sourceURL trick, so skip it if enabled.
/*@if (@_jscript) @else @*/
if (!config.isBuild) {
    text += "\r\n//@ sourceURL=" + path;
}
/*@end@*/

如果源 url 位于传递给 eval 的文本的末尾,IE 将出现语法错误。

【讨论】:

    【解决方案2】:

    @jsfellow 的回答真的很有帮助! 所示的 sn-p 位于 require-handlebars-plugin 的 hbs.js 中。 根据sourcemap proposal

    //# sourceURL=
    

    优于

    //@ sourceURL=
    

    在我更改 hbs.js 中的相应行后,所有测试浏览器(google chrome 35、firefox 30、IE 8-10)中的一切都按预期工作。 我在require-handlebars-plugin github repo 提交了一个拉取请求,目前正在合并和评估。

    我希望这对可能遇到同样问题的人有所帮助。

    【讨论】:

      【解决方案3】:

      这似乎与 JQuery 中发生的类似问题有关

      这完全是因为 DOM 没有准备好,因为 DOM 没有完全加载,所以会发生这个错误。

      如果您还没有这样做,请尝试在最后一页添加脚本或某种延迟加载:

      http://www.joezimjs.com/javascript/lazy-loading-javascript-with-requirejs/ RequireJS如何实现延迟加载? 顺便说一句,似乎微软拒绝了这方面的帖子,它并不认为这是一个错误:

      https://connect.microsoft.com/IE/feedback/details/792880/document-readystat

      【讨论】:

        猜你喜欢
        • 2011-11-25
        • 1970-01-01
        • 2013-09-18
        • 2012-07-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多