【问题标题】:AngularJS Yeoman + Grunt Build Script1014 Invalid Character IE9AngularJS Yeoman + Grunt Build Script1014 Invalid Character IE9
【发布时间】:2014-04-24 16:14:45
【问题描述】:

在 IE 9 中构建 AngularJS 项目(使用默认的 grunt uglification 和缩小设置进行测试)时出现此错误:

Script1014:无效字符

在两个不同的项目中,行和字符总是指示紧跟在第一个冒号后面的字符

:"A",

在缩小/丑化的供应商 javascript 中。

bower.json 依赖项:

"dependencies": { "angular": "1.2.6", "json3": "~3.2.6", "es5-shim": "~2.1.0", "jquery": "~1.10.2", "bootstrap": "~3.0.3", "angular-resource": "1.2.6", "angular-cookies": "1.2.6", "angular-sanitize": "1.2.6", "angular-route": "1.2.6", "moment": "~2.5.0", "ngInfiniteScroll": "1.0.0", "angular-ui": "~0.4.0", "angular-bootstrap": "~0.10.0", "components-font-awesome": "~4.0.3", "select2": "~3.4.5", "angular-animate": "1.2.6" },

index.html 供应商 js:

<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/ngInfiniteScroll/ng-infinite-scroll.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="bower_components/select2/select2.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-mocks/angular-mocks.js"></script>
<!-- endbower -->
<script src="bower_components/angular-ui/build/angular-ui.js"></script>
<!-- endbuild -->

知道可能导致问题的原因或调试此问题的最佳方法吗?非常感谢任何帮助!

【问题讨论】:

  • 您能否将您包含在 index.html 中的脚本粘贴到 vendor.js 块中?如果您已经知道此错误来自哪个文件,请也告诉我们。
  • @Stephen 谢谢,更新为在 index.html 中包含 bower.json 和供应商 js 依赖项。我将尝试深入研究并找出可能是哪个供应商 .js 文件造成问题

标签: angularjs internet-explorer-9 gruntjs yeoman minify


【解决方案1】:

这是 IE 中的 unicode 支持已知问题的结果。

为避免此问题,您可以将 ascii_only: true 选项传递给 Gruntfile.js 中的 uglify 任务。完整的 uglify 部分可能如下所示:

uglify: {
  options: {
    beautify: {
      ascii_only: true,
      quote_keys: true,
      beautify: false
    },
    preserveComments: false,
    compress: false,
    mangle: false
  },
  dist: {
    files: {
      '<%= yeoman.dist %>/scripts/scripts.js': [
        '<%= yeoman.dist %>/scripts/scripts.js'
      ]
    }
  }
}

有关这些选项的更多信息,请参阅UglifyJS API docs

【讨论】:

  • 你先生,太棒了。非常感谢!关于我可以在哪里阅读有关 ascii_only 的其他效果的任何指针?
  • 我添加了一个指向 API 文档的链接。另请参阅github.com/mishoo/UglifyJS/blob/…的源代码
  • 只是发送它 ascii_only: true 对我没有帮助。我也需要 quote_keys: true 。然后它起作用了。
【解决方案2】:

有时 IE 不喜欢在没有 HTTP 服务器的情况下运行您的网站,并可能导致此错误。您是在运行任何网络服务器还是直接在浏览器中打开 HTML?

如果在没有网络服务器的情况下运行,您可以尝试在网络服务器中运行它吗?

【讨论】:

  • 感谢@roshiro 的回复!我正在使用我不太了解的 Apache,但我假设这是一个 HTTP 服务器
  • 是的,Apache 是您的 Web 服务器。好的,所以你的问题不是我最初的想法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-24
  • 1970-01-01
  • 2016-07-28
  • 1970-01-01
  • 2013-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多