建立一个古老的有角度的项目

时间:2019-01-16 10:12:06

标签: angular typescript npm angular-cli

我无法构建旧的角度项目。我已经拉下代码,从npm install @angular/cli@1.7.4开始,ng build抛出此错误:

  

@ angular / compiler-cli和打字稿的版本不能   决心。最常见的原因是npm安装失败。

     

请确保您的package.json同时包含@ angular / compiler-cli   然后在devDependencies中输入打字稿,然后删除node_modules和   package-lock.json(如果有),然后再次运行npm install。

我不确定1.7.4将是当前的cli版本,因为package.json不包含angular / cli。 如何在不触摸代码的情况下还原此项目的所有内容?

更新

我已经将@ angular / compiler-cli @ 2.4.5和typescript@2.3.4安装到devDependencies中。这篇文章也包含更新的package.json。该错误现在显示:

  

.angular-cli.json中找不到任何应用。

那是因为我没有.angular-cli.json。不需要此文件的angular cli的最新版本是哪个?

更新2:

我创建了一个.angular-cli.json文件并尝试构建该项目。在进行一些jsonn文件修改时,我遇到了一个错误的错误:

  

TypeError:无法读取未定义的属性“ length”

我想这是来自较旧的cli / compiler / typescript版本,但是如何确定真正的问题呢?

如果我开始更新cli和其他更新,那将是一场灾难,因为我无法停止将Angular更新到7.2,这意味着很多代码更改。 (尝试过这一天,一天后就放弃了。)

package.json:

"dependencies": {
    "@angular/cli": "^1.7.4",
    "@angular/common": "^2.4.5",
    "@angular/compiler": "^2.4.5",
    "@angular/core": "^2.4.5",
    "@angular/forms": "^2.4.5",
    "@angular/http": "^2.4.5",
    "@angular/platform-browser": "^2.4.5",
    "@angular/platform-browser-dynamic": "^2.4.5",
    "@angular/platform-server": "^2.4.5",
    "@angular/router": "^3.4.5",
    "@types/node": "^6.0.42",
    "angular2-modal": "^2.0.3",
    "angular2-platform-node": "~2.0.11",
    "angular2-template-loader": "^0.6.2",
    "angular2-universal": "^2.1.0-rc.1",
    "angular2-universal-patch": "^0.2.1",
    "angular2-universal-polyfills": "^2.1.0-rc.1",
    "aspnet-prerendering": "^2.0.0",
    "aspnet-webpack": "^1.0.17",
    "awesome-typescript-loader": "^3.0.0",
    "bootstrap": "^3.3.7",
    "css": "^2.2.1",
    "css-loader": "^0.25.0",
    "es6-shim": "^0.35.1",
    "event-source-polyfill": "^0.0.7",
    "expose-loader": "^0.7.1",
    "extract-text-webpack-plugin": "^2.0.0-rc",
    "file-loader": "^0.9.0",
    "html-loader": "^0.4.4",
    "isomorphic-fetch": "^2.2.1",
    "jquery": "^2.2.4",
    "json-loader": "^0.5.4",
    "ng-select": "^1.0.0-beta.5",
    "preboot": "^4.5.2",
    "raw-loader": "^0.5.1",
    "rxjs": "^5.4.0",
    "style-loader": "^0.13.1",
    "to-string-loader": "^1.1.5",
    "url-loader": "^0.5.7",
    "webpack": "^2.2.0",
    "webpack-hot-middleware": "^2.12.2",
    "webpack-merge": "^0.14.1",
    "zone.js": "^0.7.8"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^2.4.5",
    "@types/chai": "^3.4.34",
    "@types/jasmine": "^2.5.37",
    "@types/jquery": "^2.0.41",
    "chai": "^3.5.0",
    "jasmine-core": "^2.5.2",
    "karma": "^1.3.0",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-webpack": "^1.8.0",
    "typescript": "^2.3.0"
  }

1 个答案:

答案 0 :(得分:0)

在阅读了GitHub存储库上报告的一些问题之后,我找到了解决方案。

为了更新系统中全局安装的angular-cli软件包,您需要运行:

npm卸载-g angular-cli npm缓存清理或npm缓存验证(如果npm> 5) npm install -g @ angular / cli @ latest 根据您的系统,您可能需要在上述命令前加上sudo前缀。

此外,您很可能还希望更新本地项目版本,因为在项目目录中将其选择为比全局目录更高的优先级:

rm -rf node_modules npm卸载--save-dev angular-cli npm install --save-dev @ angular / cli @ latest npm install