错误:(SystemJS)意外的标记<SyntaxError:意外的标记<eval(<anonymous>)Angular 2

我正在尝试使用angular2的整个页面,

在我的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 { } 

的index.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包

在这里input链接描述

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

plunkr我从其他堆栈溢出页面寻求帮助,并尝试了一切,但错误似乎仍然存在。

我已经在stackoverflow上发布了另一个问题的变种,这两个错误都有相同的问题。

无法在我的angular-2快速启动应用程序中加载ng2-fullpage

我不知道如何解决这个问题,现在就尝试一切。

提前致谢。

肯定有很多问题可能导致这个错误。 当我使用SystemJS连接Web服务器(例如live-server)时 ,它为单页面Web应用程序提供了一个方便的function,即将所有不存在的文件路由到项目的index.html。 因此,如果SystemJS试图解决未安装的依赖项,Web服务器将显示最常以<!DOCTYPE html>开头的index.html。 这可能是出乎意料的错误。

解:

  • 检查您的服务器是否将不存在的文件路由到HTML文件。
  • 停止debugging的路由。
  • 启动您的应用程序。 使用浏览器工具中的networking标签查找哪些文件出现404错误。
  • 使用jspm install my_dependency安装缺失的依赖jspm install my_dependency
  • 迭代,直到find所有文件。
  • 再次启用丢失的文件路由到一些HTML文件。