2017-06-21 105 views
0

所以我更新了nodejs,並在此之前發生過。角2沒有得到錯誤,它工作正常,但現在更新node_modules它停止工作,我不知道錯誤將在哪裏或如何解決它。角度2意外令牌錯誤

(index):29 Error: (SystemJS) Unexpected token < 
    SyntaxError: Unexpected token < 
     at eval (<anonymous>) 
     at Object.eval (http://localhost:3000/app/services/authentication.service.js:15:22) 
     at eval (http://localhost:3000/app/services/authentication.service.js:70:4) 
     at eval (http://localhost:3000/app/services/authentication.service.js:71:3) 
    Evaluating http://localhost:3000/node_modules/angular2-jwt/angular2-jwt.js 
    Evaluating http://localhost:3000/app/services/authentication.service.js 
    Evaluating http://localhost:3000/app/profile/profile.component.js 
    Evaluating http://localhost:3000/app/app.module.js 
    Evaluating http://localhost:3000/app/main.js 
    Error loading http://localhost:3000/app/main.js 
     at eval (<anonymous>) 
     at Object.eval (http://localhost:3000/app/services/authentication.service.js:15:22) 
     at eval (http://localhost:3000/app/services/authentication.service.js:70:4) 
     at eval (http://localhost:3000/app/services/authentication.service.js:71:3) 
    Evaluating http://localhost:3000/node_modules/angular2-jwt/angular2-jwt.js 
    Evaluating http://localhost:3000/app/services/authentication.service.js 
    Evaluating http://localhost:3000/app/profile/profile.component.js 
    Evaluating http://localhost:3000/app/app.module.js 
    Evaluating http://localhost:3000/app/main.js 
    Error loading http://localhost:3000/app/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', 
     // other libraries 
     'rxjs':      'npm:rxjs', 
     'angular2-jwt': 'node_modules/angular2-jwt/angular2-jwt.js', 
     'angular-in-memory-web-api': 'npm:angular-in-memory-web-api', 
    }, 
    // packages tells the System loader how to load when no filename and/or no extension 
    packages: { 
     app: { 
     main: './main.js', 
     defaultExtension: 'js' 
     }, 
     rxjs: { 
     defaultExtension: 'js' 
     }, 
     'angular-in-memory-web-api': { 
     main: './index.js', 
     defaultExtension: 'js' 
     } 
    } 
    }); 
})(this); 

的index.html

<html> 
    <head> 
    <title>Vietnam Films</title> 
    <base href="/"> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"> 
    <link rel="stylesheet" href="assets/ecommerce.css"> 

    <!-- 1. Load libraries --> 
    <!-- 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/reflect-metadata/Reflect.js"></script> 
    <script src="node_modules/systemjs/dist/system.src.js"></script> 

    <script src="node_modules/jquery/dist/jquery.min.js"></script> 
    <script src="node_modules/tether/dist/js/tether.min.js"></script> 
    <script src="node_modules/bootstrap/dist/js/bootstrap.js"></script> 
    <script src="https://www.paypalobjects.com/api/checkout.js"></script> 



    <!-- 2. Configure SystemJS --> 
    <script src="systemjs.config.js"></script> 
    <script> 
     System.import('app').catch(function(err){ console.error(err); }); 
    </script> 
    <script src="//cdn.auth0.com/js/lock-9.0.min.js"></script> 
    </head> 

    <!-- 3. Display the application --> 
    <body> 
    <my-app></my-app> 



    <div class="loading"> 
     <h1>Loading...</h1> 
    </div> 


    </body> 
</html> 

tsconfig.json

{ 
    "compilerOptions": { 
    "module": "commonjs", 
    "target": "es5", 
    "sourceMap": true 
    }, 
    "exclude": [ 
    "node_modules" 
    ] 
} 
+0

有一個很好的機會,你實際上在某些文件上找到404未找到錯誤。當然,對於Angular,我們應該將404重定向到index.html頁面,您可能正在做的正確。要查看是否屬於這種情況,請將Web服務器配置爲實際返回404以查看哪個文件丟失。或者查看瀏覽器開發工具中的網絡流量,看看是否有任何請求正在返回index.html頁面而不是正確的文件。 –

+0

我終於發現錯誤,鉻瀏覽器控制檯太模糊,我看着Firefox控制檯,它說我錯過了一個節點模塊。 –

回答

0

開發工具是你的朋友。訪問該頁面時打開Chrome開發工具並檢查網絡選項卡。看看個人的要求。我猜測http://localhost:3000/app/services/authentication.service.js請求沒有返回你希望的JavaScript,而是返回一個HTML錯誤頁面。看看那個錯誤是什麼,你會發現罪魁禍首。很有可能它根本找不到該文件(HTTP 404),但最好檢查錯誤。

如果它是404,請確保authentication.service.js正確地位於您提供的應用程序/服務目錄中。