代码之家  ›  专栏  ›  技术社区  ›  porgo

部署Angular 2应用程序后出错

  •  0
  • porgo  · 技术社区  · 9 年前

    https://angular.io/guide/deployment

    但当我把所有文件放在主机上时,浏览器控制台会出错:

    Error: (SystemJS) Unexpected token <
    SyntaxError: Unexpected token <
        at eval (<anonymous>)
        at ZoneDelegate.invoke (https://unpkg.com/zone.js@0.8.4?main=browser:365:26)
        at Zone.run (https://unpkg.com/zone.js@0.8.4?main=browser:125:43)
        at https://unpkg.com/zone.js@0.8.4?main=browser:760:57
        at ZoneDelegate.invokeTask (https://unpkg.com/zone.js@0.8.4?main=browser:398:31)
    

    这是我的索引。html文件:

    <!DOCTYPE html>
    <html>
      <head>
        <!-- Doesn't load from node_modules! -->
    
        <!-- Set the base href -->
        <base href="/">
        <title>Simple Deployment</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="styles.css">
    
        <!-- Polyfills -->
        <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    
        <!-- Update these package versions as needed -->
        <script src="https://unpkg.com/zone.js@0.8.4?main=browser"></script>
        <script src="https://unpkg.com/systemjs@0.19.39/dist/system.src.js">    </script>
    
        <!-- This SystemJS configuration loads umd packages from the web -->
        <script src="systemjs.config.server.js"></script>
    
        <script>
          System.import('main.js')
                .catch(function(err){ console.error(err); });
        </script>
      </head>
    
      <body>
        <my-app>loading...</my-app>
      </body>
    
    </html>
    

    和systemjs。配置文件:

    /**
     * System configuration for Angular samples
     * Adjust as necessary for your application needs.
     */
    (function (global) {
      System.config({
        paths: {
          'npm:': 'https://unpkg.com/' // path serves as alias
        },
        // map tells the System loader where to look for things
        map: {
          // our app is within the app folder
          'app': 'app',
    
          // angular bundles
          '@angular/core': 'npm:@angular/core/bundles/core.umd.min.js',
          '@angular/common': 'npm:@angular/common/bundles/common.umd.min.js',
          '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.min.js',
          '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.min.js',
          '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.min.js',
          '@angular/http': 'npm:@angular/http/bundles/http.umd.min.js',
          '@angular/router': 'npm:@angular/router/bundles/router.umd.min.js',
          '@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.min.js',
          '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.min.js',
          '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.min.js',
          '@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.min.js',
    
          // other libraries
          'rxjs':                      'npm:rxjs',
          'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
          app: {
            defaultExtension: 'js',
            meta: {
              './*.js': {
                loader: 'systemjs-angular-loader.js'
              }
            }
          },
          rxjs: {
            defaultExtension: 'js'
          }
        }
      });
    })(this);
    

    <script src="systemjs.config.server.js"></script>
    
    <script>
      System.import('main.js')
            .catch(function(err){ console.error(err); });
    </script>
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   porgo    9 年前

    好的,我找到了这个问题的解决方案。

    我移动了索引。html文件放入根文件夹并更改了基本href:

    <base href="/src/app">
    
    推荐文章