角度2意外令牌错误
问题描述:
所以我更新了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"
]
}
答
开发工具是你的朋友。访问该页面时打开Chrome开发工具并检查网络选项卡。看看个人的要求。我猜测http://localhost:3000/app/services/authentication.service.js
请求没有返回你希望的JavaScript,而是返回一个HTML错误页面。看看那个错误是什么,你会发现罪魁祸首。很有可能它根本找不到该文件(HTTP 404),但最好检查错误。
如果它是404,请确保authentication.service.js正确地位于您提供的应用程序/服务目录中。
有一个很好的机会,你实际上在某些文件上找到404未找到错误。当然,对于Angular,我们应该将404重定向到index.html页面,您可能正在做的正确。要查看是否属于这种情况,请将Web服务器配置为实际返回404以查看哪个文件丢失。或者查看浏览器开发工具中的网络流量,看看是否有任何请求正在返回index.html页面而不是正确的文件。 –
我终于发现错误,铬浏览器控制台太模糊,我看着Firefox控制台,它说我错过了一个节点模块。 –