簡體   English   中英

錯誤:(SystemJS) 意外標記 &lt; SyntaxError: Unexpected token &lt; at eval (<anonymous> ) 角 2

[英]Error: (SystemJS) Unexpected token < SyntaxError: Unexpected token < at eval (<anonymous>) Angular 2

我正在嘗試使用角度為 2 的整頁,

在我的 app.module.ts 中導入它時出現以下錯誤。

"(SystemJS) Unexpected token <
    SyntaxError: Unexpected token <
        at eval (<anonymous>)
        at Object.eval (http://localhost:3000/app/app.module.js:16:22)
        at eval (http://localhost:3000/app/app.module.js:40:4)
        at eval (http://localhost:3000/app/app.module.js:41:3)
        at eval (<anonymous>)
    Evaluating http://localhost:3000/node_modules/ng2-fullpage
    Evaluating http://localhost:3000/app/app.module.js
    Evaluating http://localhost:3000/main.js
    Error loading http://localhost:3000/main.js"

以下是我的文件:

systemjs.config.js

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // 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.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      // '@jquery':'npm:jquery/jquery.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',
      'ng2-fullpage':               'npm:ng2-fullpage',
      // 'jquery':                     'npm:jquery/dist/jquery.js',
      'fullpage.js':                'npm:fullpage.js/jquery.fullPage.js'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        // format:'register',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {HttpModule} from '@angular/http';
import {routing} from './app.routing';
import {NavbarComponent} from './components/navbar/navbar.component';
import { MnFullpageDirective } from 'ng2-fullpage';
import {MnFullpageService} from 'ng2-fullpage';

import { AppComponent }  from './app.component';
import { ResumeComponent } from './components/resume/resume.component';
import { AboutComponent } from './components/about/about.component';
import {HomeComponent} from './components/home/home.component';



@NgModule({
  imports:      [ BrowserModule,HttpModule, routing ],
  declarations: [ AppComponent, ResumeComponent, AboutComponent, HomeComponent, NavbarComponent,
    MnFullpageDirective
  ],
  bootstrap:    [ AppComponent ],
  providers: [MnFullpageService]
})
export class AppModule { }

索引.html

<!DOCTYPE html>
<html>
  <head>
    <title>Nakul Chawla</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://bootswatch.com/cyborg/bootstrap.min.css" />
    <link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="styles.css">
    <!--<link rel="stylesheet" href="../node_modules/fullpage.js/dist/jquery.fullpage.css" />-->
    <!--<script src="node_modules/jquery/jquery.js"></script>-->

    <!-- Polyfill(s) for older browsers -->
    <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/systemjs/dist/system.src.js"></script>

    <script src="systemjs.config.js"></script>
    <script src="node_modules/jquery/dist/jquery.min.js"></script>
    <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
    <script>
      System.import('main.js').catch(function(err){ console.error(err); });
    </script>
  </head>

  <body>
  <base href="/">
    <my-app>Loading AppComponent content here ...</my-app>
  </body>
</html>

我正在從引用 plunkr 的 npm 頁面獲取幫助:

npm 包

在此處輸入鏈接描述

http://embed.plnkr.co/1p9zKp4CNI1HncAh1h9m

plunkr我從其他堆棧溢出頁面尋求幫助並嘗試了所有方法,但錯誤似乎仍然存在。

我在 stackoverflow 上發布了該問題的另一個變體,兩個錯誤都有相同的問題。

無法在我的 angular-2 快速入門應用程序中加載 ng2-fullpage

我不知道如何解決這個問題,現在嘗試了一切。

提前致謝。

肯定有很多問題可能會導致此錯誤。 我在將 SystemJS 與 Web 服務器(例如live-server)結合使用時得到了它,這些服務器為單頁 Web 應用程序提供了一個方便的功能,即將所有不存在的文件路由到項目的 index.html。 因此,如果 SystemJS 嘗試解析未安裝的依賴項,網絡服務器將顯示最常以<!DOCTYPE html>開頭的 index.html。 這可能是錯誤中提到的意外<

解決方案:

  • 檢查您的服務器是否將不存在的文件路由到 html 文件。
  • 停止路由以進行調試。
  • 啟動您的應用程序。 使用瀏覽器工具中的網絡選項卡找出哪些文件出現 404 錯誤。
  • 使用jspm install my_dependency安裝缺少的依賴jspm install my_dependency
  • 迭代直到可以找到所有文件。
  • 再次啟用將丟失文件路由到某個 html 文件的功能。

暫無
暫無

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

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