Angular2 Final Release - “Error: Angular requires Zone.js prolyfill”

前端 未结 5 757
醉话见心
醉话见心 2021-02-18 16:09

I have upgraded from RC4 to the Final release of Angular2. When I run npm start, the app is stuck on \'Loading...\' the only error I get is about Zone.js:

<

相关标签:
5条回答
  • 2021-02-18 16:57

    This can happen if the order of scripts is incorrect.

    <!-- ERROR: Angular requires Zone.js polyfill -->
    <script src="main.js"></script>
    <script src="runtime.js"></script>
    <script src="polyfills.js"></script>
    

    Correct order:

    <!-- Success -->
    <script src="runtime.js"></script>
    <script src="polyfills.js"></script>
    <script src="main.js"></script>
    
    0 讨论(0)
  • 2021-02-18 16:59

    Add import 'zone.js' on top of the file main.ts.

    I was trying to include serviceWorkers.

    0 讨论(0)
  • 2021-02-18 17:02

    This error can also occur when reverting a commit or changing a lot of files and not restarting the development server. Just stop the angular cli server, and try running ng serve again. This solution worked for me, and it wasn't obvious to restart the angular development server at first.

    0 讨论(0)
  • 2021-02-18 17:03

    You need to include Zone as a script tag before you include angular, it doesn't get loaded as a module. See https://angular.io/guide/quickstart

    <!-- 1. Load libraries -->
    
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    
    0 讨论(0)
  • 2021-02-18 17:09

    If adding node_module to your HTML is a problem, all you need is to manually import zone.js before bootstrapping.

    import 'zone.js';
    ...
    platformBrowserDynamic().bootstrapModule(AppModule);
    
    0 讨论(0)
提交回复
热议问题