【问题标题】:Angular2 : how to prevent exception on specific file like zone.js?Angular2:如何防止 zone.js 等特定文件出现异常?
【发布时间】:2016-12-01 14:30:11
【问题描述】:

我使用 Visual Studio Code 开发和调试 Angular 2 应用程序,附加到 Chrome (v 48) 以进行调试。

每次我启动应用程序时都会出现异常:

fetchPromise = global['fetch']();

每次我使用调试器启动我的应用程序时,是否有避免在该异常上停止调试器的技巧?

这是 zone.js 中我有异常的代码:

if (NativePromise) {
    patchThen(NativePromise);
    if (typeof global['fetch'] !== 'undefined') {
        var fetchPromise = void 0;
        try {
            // In MS Edge this throws
            fetchPromise = global['fetch']();   // <== Exception HERE 
        }
        catch (e) {
            // In Chrome this throws instead.
            fetchPromise = global['fetch']('about:blank');
        }

我在package.json中使用了zone.js v0.6.26,我更新到0.7.2还是有异常。

【问题讨论】:

  • 暂时提到了这个here,如果有任何更新,都会通知您。

标签: javascript google-chrome angular visual-studio-code


【解决方案1】:

感谢 roblouren here 发布并由 LEOTM 链接的建议。将文件zone.js 添加到launch.jsonexpertimentalSkipDiles 选项是解决这个恼人异常的完美解决方案。

异常仍然存在,但不会在每次编译和更新代码时在屏幕上弹出。

在 Visual Studio Code 项目的 launch.json 中:

{
    "version": "0.2.0",
    "configurations": [{
            "name": "Launch Chrome against localhost, with sourcemaps",
            "type": "chrome",
            "request": "launch",
            "url": "http://localhost:3000",
            "sourceMaps": true,
            "webRoot": "${workspaceRoot}",
            "experimentalSkipFiles": [
                "zone.js"
            ]
        }

【讨论】:

    【解决方案2】:

    在您的 launch.json 配置中添加 "skipFiles":["vendor.bundle.js"] 将为您修复它

    【讨论】:

      猜你喜欢
      • 2010-10-22
      • 1970-01-01
      • 1970-01-01
      • 2023-02-15
      • 2013-11-12
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 2018-12-23
      相关资源
      最近更新 更多