我前一段时间开始关注Angular2教程。现在,我又回到了Routing chapter上,看来该教程已稍作更新,我不得不回过头将package.json
更新为current version,否则app.routes.ts
文件将无法编译。现在它可以正常编译,但是当我运行该应用程序时,脚本在运行时崩溃,显然是在Zone.js包内:
我已经检查过,并且platform-browser-dynamic.umd.js
文件确实在磁盘上不存在。
这是新的package.json
文件:
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/forms": "0.2.0",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "3.0.0-beta.1",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.4",
"systemjs": "0.19.27",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"angular2-in-memory-web-api": "0.0.14",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": "^2.2.0",
"typescript": "^1.8.10",
"typings":"^1.0.4"
}
}
我尝试使用the longer version from the tutorial's GitHub repository,但错误是相同的。尽管原始的GitHub项目可以正常运行。
我确保
<script
中的index.html
>标签与GitHub上的标签匹配:<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="systemjs.config.js"></script>
我的
typings.json
文件:{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
"jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
"node": "registry:dt/node#4.0.0+20160509154515"
}
}
如何摆脱这个错误?到目前为止,我的Angular2经验包括像猴子一样从教程中复制代码,我真的不太了解此错误与...有关。
最佳答案
您的Angular2应用程序无法将platform-browser-dynamic.umd.js
以及其他umd捆绑包as they were moved加载到bundles/
中的2.0.0-rc.2
子目录中。
正如您已经注意到的那样,您的错误在system.config.js
内部,因为它正尝试使用错误的路径(see here)加载umd捆绑包。
复制新的配置文件应该已经添加了'/bundles/' +
部分,它确实解决了您的问题。