我已从RC4升级到Angular2的最终版本。当我运行npm start
时,该应用仍停留在“正在加载...”#39;我得到的唯一错误是关于Zone.js:
基本上,typeof Zone
未定义:
这是我的package.json:
"engines": {
"node": ">= 4.2.1",
"npm": "3.10.7"
},
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/platform-server": "2.0.0",
"@angular/router": "3.0.0",
"@salesforce-ux/design-system": "^2.0.3",
"angular2-busy": "^0.3.2-rc.6",
"chart.js": "2.1.0",
"core-js": "^2.4.0",
"d3": "^4.2.3",
"lodash": "^4.14.0",
"moment": "^2.14.1",
"ng2-bootstrap": "^1.1.4",
"ng2-charts": "^1.1.0",
"ng2-datepicker": "^1.0.6",
"ng2-pagination": "^0.4.1",
"normalize.css": "^4.1.1",
"rxjs": "5.0.0-beta.12",
"typescript": "2.1.0-dev.20160916",
"zone.js": "0.6.21"
},
"devDependencies": {
"@angular/compiler-cli": "^0.6.1",
"@types/core-js": "^0.9.28",
"@types/hammerjs": "^2.0.28",
"@types/jasmine": "^2.2.29",
"@types/lodash": "^4.14.34",
"@types/node": "^6.0.38",
"@types/source-map": "^0.1.26",
"@types/webpack": "^1.12.29",
"angular2-hmr": "~0.6.0",
"awesome-typescript-loader": "~0.17.0",
"compression-webpack-plugin": "^0.3.1",
"copy-webpack-plugin": "^2.1.3",
"css-loader": "^0.23.1",
"es6-promise": "^3.1.2",
"es6-promise-loader": "^1.0.1",
"es6-shim": "^0.35.0",
"es7-reflect-metadata": "^1.6.0",
"exports-loader": "^0.6.3",
"expose-loader": "^0.7.1",
"file-loader": "^0.8.5",
"html-webpack-plugin": "^2.15.0",
"http-server": "^0.9.0",
"imports-loader": "^0.6.5",
"jasmine": "^2.4.1",
"json-loader": "^0.5.4",
"object-assign": "4.0.1",
"phantomjs-polyfill": "0.0.1",
"raw-loader": "0.5.1",
"source-map-loader": "^0.1.5",
"style-loader": "^0.13.1",
"ts-helpers": "1.1.1",
"ts-node": "^0.7.1",
"tslint": "^3.7.1",
"tslint-loader": "^2.1.3",
"typescript": "2.0.0",
"url-loader": "^0.5.7",
"wallaby-webpack": "0.0.11",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-md5-hash": "^0.0.5",
"webpack-merge": "^0.12.0"
}
}
我已尝试过zone.js ^ 0.6.23和these package versions as well.有什么想法吗?我可以编辑和添加更多信息。
编辑:我在CHANGELOG找到的唯一线索是this from RC 6:
测试配置:由于zone.js对等依赖项升级,加载各种区域规范的顺序已更改。请参阅this example Karma config.
编辑:我尝试在index.html
中的脚本标记中导入Zone.js,即使我有node_modules中的包,我也会收到这些错误:
答案 0 :(得分:16)
如果脚本顺序不正确,则会发生这种情况。
<!-- ERROR: Angular requires Zone.js polyfill -->
<script src="main.js"></script>
<script src="runtime.js"></script>
<script src="polyfills.js"></script>
正确的订单
<!-- Success -->
<script src="runtime.js"></script>
<script src="polyfills.js"></script>
<script src="main.js"></script>
答案 1 :(得分:13)
在包含角度之前,您需要将区域包含为脚本标记,它不会作为模块加载。看到 https://angular.io/guide/quickstart
<!-- 1. Load libraries -->
<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>
答案 2 :(得分:6)
如果在HTML中添加node_module
是个问题,那么您只需在引导前手动导入zone.js
。
import 'zone.js';
...
platformBrowserDynamic().bootstrapModule(AppModule);
答案 3 :(得分:1)
在文件import 'zone.js'
的顶部添加main.ts
。
我试图包括serviceWorkers。
答案 4 :(得分:0)
还原提交或更改大量文件并且不重新启动开发服务器时,也会发生此错误。只需停止angular cli服务器,然后尝试再次运行ng serve。该解决方案对我有用,而且一开始重启角开发服务器并不明显。
答案 5 :(得分:0)
我得到了错误:
Error: In this configuration Angular requires Zone.js
at new NgZone (core.js:26974)
at getNgZone (core.js:27786)
at PlatformRef.bootstrapModuleFactory (core.js:27675)
at core.js:27726
解决方案:
只需将**import 'zone.js';**
添加到您的main.ts文件中。
就像魅力一样。