我正在try 将我的Angular 2项目从2.0.0
升级到2.4.1
.据我所知,语义版本控制从2.0.0
版开始就被采用了,2.x.x
版应该是替代版本.我的经验似乎表明并非如此.也许我只是不知道我在做什么,但我没有发现这是直截了当的……
try 1-手动版本升级
我天真的第一个方法是手动更新我的@angular
个依赖项.您可以参考下面的My Package.json(更新1).我做了这些更改,然后做了npm install
,我得到了几个警告,然后当我try 做ng serve
时,得到了以下错误.
无法读取未定义的属性"AssetUrl"
我的警告是...
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.0.15: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN @angular/core@2.4.1 requires a peer of rxjs@^5.0.1 but none was installed.
npm WARN @angular/core@2.4.1 requires a peer of zone.js@^0.7.2 but none was installed.
npm WARN @angular/http@2.4.1 requires a peer of rxjs@^5.0.1 but none was installed.
npm WARN @angular/compiler-cli@0.6.4 requires a peer of @angular/compiler@2.0.2 but none was installed.
npm WARN @angular/compiler-cli@0.6.4 requires a peer of @angular/platform-server@2.0.2 but none was installed.
npm WARN @angular/compiler-cli@0.6.4 requires a peer of @angular/core@2.0.2 but none was installed.
npm WARN @ngtools/webpack@1.2.1 requires a peer of @angular/compiler-cli@^2.3.1 but none was installed.
npm WARN @ngtools/webpack@1.2.1 requires a peer of @angular/tsc-wrapped@^0.5.0 but none was installed.
npm WARN @ngtools/webpack@1.2.1 requires a peer of webpack@^2.1.0-beta.25 but none was installed.
因此,我试图修复这些警告,但我不知道如何修复所有警告(例如@ngtools/webpack),其中一些警告似乎相互冲突.所以我放弃了手动更新angular 2版本的方法...
Original package.json
{
"name": "frontend",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"build": "ng build",
"buildProd": "ng build --env=prod"
},
"private": true,
"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/material": "^2.0.0-alpha.9-experimental-pizza",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@types/google-libphonenumber": "^7.4.8",
"angular2-datatable": "^0.4.2",
"apollo-client": "^0.4.22",
"core-js": "^2.4.1",
"google-libphonenumber": "^2.0.4",
"graphql-tag": "^0.1.15",
"hammerjs": "^2.0.8",
"ng2-bootstrap": "^1.1.16",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.2",
"zone.js": "^0.6.26"
},
"devDependencies": {
"@types/hammerjs": "^2.0.33",
"@types/jasmine": "^2.2.30",
"@types/lodash": "^4.14.39",
"angular-cli": "1.0.0-beta.16",
"codelyzer": "~0.0.26",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.9",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.2",
"typings": "1.4.0"
}
}
Update 1 of package.json
{
"name": "frontend",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"build": "ng build",
"buildProd": "ng build --env=prod"
},
"private": true,
"dependencies": {
"@angular/common": "2.4.1",
"@angular/compiler": "2.4.1",
"@angular/core": "2.4.1",
"@angular/forms": "2.4.1",
"@angular/http": "2.4.1",
"@angular/material": "^2.0.0-alpha.9-experimental-pizza",
"@angular/platform-browser": "2.4.1",
"@angular/platform-browser-dynamic": "2.4.1",
"@angular/router": "3.0.0",
"@types/google-libphonenumber": "^7.4.8",
"angular2-datatable": "^0.4.2",
"apollo-client": "^0.4.22",
"core-js": "^2.4.1",
"google-libphonenumber": "^2.0.4",
"graphql-tag": "^0.1.15",
"hammerjs": "^2.0.8",
"ng2-bootstrap": "^1.1.16",
"rxjs": "5.0.1",
"ts-helpers": "^1.1.2",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@types/hammerjs": "^2.0.33",
"@types/jasmine": "^2.2.30",
"@types/lodash": "^4.14.39",
"angular-cli": "1.0.0-beta.16",
"codelyzer": "~0.0.26",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.9",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.2",
"typings": "1.4.0"
}
}
try 2-使用npm判断更新
因为当我试图为更新挑选Angular 依赖项时,我最终遇到了一个蜘蛛网,里面有其他需要更新的依赖项,接下来我try 只更新所有内容.
基于this answer,我try 了以下方法:
npm i -g npm-check-updates
npm-check-updates -u
npm install
这很好,但当我try ng serve时,我得到了以下错误:
AppModule中的错误不是NgModule
使用收集到的信息,我降低了打字脚本的版本,这个错误消失了,但出现了一个新的错误.
静态解析符号值时遇到错误.
我一直在努力克服这些错误,但事实上,我有这么多的麻烦是提高危险信号.
Can anybody help? Am I taking the wrong approach?
注意,我看到了一些关于更新angular cli项目的建议,建议卸载angular cli并重新安装,然后执行ng init并覆盖配置文件.这对我不起作用,因为我已经有了最新版本.
Edit: The statement about having the latest angular-cli was incorrect. I had 100 whereas the latest at the time of this edit is 101. Nevertheless, I did try to update my angular-cli and run ng init on my existing project. I notice now that I didn't follow the steps outlined on the angular-cli github page precisely. I skipped the 102, and I blew away all my node_modules instead of using the rm command they outline.