簡體   English   中英

為什么Angular 12 調整polyfill.ts 后在Edge 或Firefox 中運行不了?

[英]Why won't Angular 12 run in Edge or Firefox after adjusting polyfill.ts?

我有一個在 Angular 12 中運行的應用程序,它在 Firefox 和 Edge 中顯示空白屏幕,但在 Chrome 中運行。

我已按照 polyfill.ts 中的說明進行操作

導入“classlist.js”; // 運行npm install --save classlist.js 導入“網絡動畫-js”; // 運行npm install --save web-animations-js

我的package.json看起來像這樣

    {
      "name": "project-name",
      "version": "0.0.0",
      "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "watch": "ng build --watch --configuration development",
        "test": "ng test"
      },
      "private": true,
      "dependencies": {
        "@angular/animations": "~12.2.0",
        "@angular/cdk": "^12.2.7",
        "@angular/common": "~12.2.0",
        "@angular/compiler": "~12.2.0",
        "@angular/core": "~12.2.0",
        "@angular/flex-layout": "^12.0.0-beta.35",
        "@angular/forms": "~12.2.0",
        "@angular/material": "^12.2.7",
        "@angular/platform-browser": "~12.2.0",
        "@angular/platform-browser-dynamic": "~12.2.0",
        "@angular/router": "~12.2.0",
        "ajv": "^8.6.3",
        "animate.css": "^4.1.1",
        "classlist.js": "^1.1.20150312",
        "core-js": "^2.6.12",
        "hammerjs": "^2.0.8",
        "material-icons": "^1.5.1",
        "ngx-cookie-service": "^12.0.3",
        "ngx-trim-directive": "^1.1.0",
        "rxjs": "~6.6.0",
        "tslib": "^2.3.0",
        "web-animations-js": "^2.3.2",
        "zone.js": "~0.11.4"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "~12.2.7",
        "@angular/cli": "~12.2.7",
        "@angular/compiler-cli": "~12.2.0",
        "@types/jasmine": "~3.8.0",
        "@types/node": "^12.11.1",
        "jasmine-core": "~3.8.0",
        "karma": "~6.3.0",
        "karma-chrome-launcher": "~3.1.0",
        "karma-coverage": "~2.0.3",
        "karma-jasmine": "~4.0.0",
        "karma-jasmine-html-reporter": "~1.7.0",
        "typescript": "~4.3.5"
      }
    }

這是我的 polyfill

    /**
     * This file includes polyfills needed by Angular and is loaded before the app.
     * You can add your own extra polyfills to this file.
     *
     * This file is divided into 2 sections:
     *   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
     *   2. Application imports. Files imported after ZoneJS that should be loaded before your main
     *      file.
     *
     * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
     * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
     * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
     *
     * Learn more in https://angular.io/guide/browser-support
     */

    /***************************************************************************************************
     * BROWSER POLYFILLS
     */

    /**
     * IE11 requires the following for NgClass support on SVG elements
     */
    import 'classlist.js';  // Run `npm install --save classlist.js`.

    /**
     * Web Animations `@angular/platform-browser/animations`
     * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
     * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
     */
    import 'web-animations-js';  // Run `npm install --save web-animations-js`.

    /**
     * By default, zone.js will patch all possible macroTask and DomEvents
     * user can disable parts of macroTask/DomEvents patch by setting following flags
     * because those flags need to be set before `zone.js` being loaded, and webpack
     * will put import in the top of bundle, so user need to create a separate file
     * in this directory (for example: zone-flags.ts), and put the following flags
     * into that file, and then add the following code before importing zone.js.
     * import './zone-flags';
     *
     * The flags allowed in zone-flags.ts are listed here.
     *
     * The following flags will work for all browsers.
     *
     * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
     * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
     * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
     *
     *  in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
     *  with the following flag, it will bypass `zone.js` patch for IE/Edge
     *
     *  (window as any).__Zone_enable_cross_context_check = true;
     *
     */

    /***************************************************************************************************
     * Zone JS is required by default for Angular itself.
     */
    import 'zone.js';  // Included with Angular CLI.

為什么腳本不會在 Edge 和 Firefox 中運行?

polyfill.ts不再是必需的,因為

這是您在pollyfill.ts文件中唯一需要的部分

/***************************************************************************************************
 * Zone JS is required by default for Angular itself.
 */
import 'zone.js' // Included with Angular CLI.

/***************************************************************************************************

一切都應該工作得很好,所以請做

npm un classlist.js & npm un web-animations-js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM