【发布时间】:2017-06-30 08:47:52
【问题描述】:
每个人。 我正在尝试将编写在角度 1 上的大型应用程序升级到角度 2。作为第一步,它尝试使用 official guide 创建混合角度 1/2 应用程序。
当所有指令完成后我得到一个错误
Unhandled Promise rejection: (SystemJS) Unexpected token <
SyntaxError: Unexpected token <
at eval (<anonymous>)
at ZoneDelegate.invoke (http://localhost:8000/node_modules/zone.js/dist/zone.js:242:26)
at Zone.run (http://localhost:8000/node_modules/zone.js/dist/zone.js:113:43)
at http://localhost:8000/node_modules/zone.js/dist/zone.js:535:57
at ZoneDelegate.invokeTask (http://localhost:8000/node_modules/zone.js/dist/zone.js:275:35)
at Zone.runTask (http://localhost:8000/node_modules/zone.js/dist/zone.js:151:47)
at drainMicroTaskQueue (http://localhost:8000/node_modules/zone.js/dist/zone.js:433:35)
at XMLHttpRequest.ZoneTask.invoke (http://localhost:8000/node_modules/zone.js/dist/zone.js:349:25)
Evaluating http://localhost:8000/app
Error loading http://localhost:8000/app ; Zone: <root> ; Task: Promise.then ; Value:
我的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',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.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'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
我在 package.config 中的依赖项
"dependencies": {
"@angular/common": "~2.4.0",
"@angular/compiler": "~2.4.0",
"@angular/core": "~2.4.0",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "~2.4.0",
"@angular/platform-browser-dynamic": "~2.4.0",
"@angular/router": "~3.4.0",
"@angular/upgrade": "~2.4.0",
"angular-in-memory-web-api": "~0.2.4",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.7.4"
},
有人可以帮我解决这个问题吗?
【问题讨论】:
-
你的代码中有api请求吗?查看网络选项卡以检查 api 请求是否失败。当 api 未发送有效数据时,我大多在开发过程中遇到此错误。
-
是的,你是对的。当
zone.js响应http://localhost:8000/app时出现错误。服务器返回文件夹结构。但我不知道如何解决它。 -
那么,您能否在 api 请求中添加响应以及预期响应和其他相关内容?
-
请求由
zone.js库发送,问题是我现在没有预期的响应。我认为这是错误的 url,因为它是一个没有服务器端的单页应用程序。来自url的回复是<html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Index of /app/</title> </head> <body> <h1>Index of /app/</h1> <table><tr><td><code>(drwxr-xr-x)</code></td><td style="text-align: right; padding-left: 1em"><code></code></td><td style="padding-left: 1em"><a href="/app/../">..... -
是否有任何更新,面临同样的问题,从 angularjs 1 升级到 angular 5?
标签: angularjs angular upgrade systemjs