我正在尝试将我的angular 2项目从升级2.0.0
到2.4.1
。我知道自从2.0.0
发布以来就已经采用了语义版本控制,2.x.x
发布应该是直接替代。我的经验似乎表明并非如此。也许我只是不知道自己在做什么,但我没有发现这很简单...
尝试1-手动版本升级
我幼稚的第一种方法是手动更新@angular
依赖项。您可以在下面引用我的package.json(更新1)。我进行了这些更改,然后执行了,npm install
并且收到了一些警告,然后在尝试执行时遇到了以下错误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版本的方法...
原始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"
}
}
package.json的更新1
{
"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"
}
}
尝试2-使用npm-check-updates
因为当我尝试挑选我的角度依赖项进行更新时,我最终陷入了需要更新的其他依赖项的蜘蛛网中,所以我接下来尝试仅更新所有内容。
基于此答案,我尝试了以下操作:
npm i -g npm-check-updates
npm-check-updates -u
npm install
这很好,但是当我尝试ng服务时,出现以下错误:
AppModule中的错误不是NgModule
使用此处收集的信息,我将打字稿版本降级,该错误消失了,但是弹出了一个新错误。
ERROR in Error遇到静态解析符号值的错误。引用非导出函数(原始.ts文件中的位置29:10),在rest-paths.ts中解析符号restPaths,在app.module.ts中解析符号AppModule,在app.module.ts中解析符号AppModule
我一直在努力克服这些错误,但是我遇到很多麻烦的事实是在发出危险信号。
有人可以帮忙吗?我采用错误的方法吗?
请注意,我已经看到一些有关更新angular-cli项目的建议,这些建议建议先卸载angular-cli并重新安装它,然后执行ng init并覆盖您的配置文件。这对我不起作用,因为我已经有了最新版本。
编辑:关于具有最新的angular-cli的声明不正确。我angular-cli version 1.0.0-beta.16
在编辑时最新的是1.0.0-beta.24
。不过,我确实尝试更新我的angular-cli并在现有项目上运行init。我现在注意到,我没有完全按照angular-cli github页面上概述的步骤进行操作。我跳过了npm install --save-dev angular-cli@latest
,我删除了所有的node_modules而不是使用它们概述的rm命令。