0
votes

I can not build an old angular project. I have pulled down the code, started with npm install @angular/[email protected] and ng build throws this error:

Versions of @angular/compiler-cli and typescript could not be determined. The most common reason for this is a broken npm install.

Please make sure your package.json contains both @angular/compiler-cli and typescript in devDependencies, then delete node_modules and package-lock.json (if you have one) and run npm install again.

I'm not sure that 1.7.4 would be the corrent cli version as package.json doesn't contain angular/cli. How can I restore everything for this project to build without touching the code?

Update:

I have installed @angular/[email protected] and [email protected] into devDependencies. This post contains the updated package.json, too. The error now says:

Unable to find any apps in .angular-cli.json.

That's because I don't have .angular-cli.json. Which was the last version of angular cli that did't need this file?

Update 2:

I've created an .angular-cli.json file and tried to build the project. Ater some jsonn file modifications I got a misterious error:

TypeError: Cannot read property 'length' of undefined

I suppose this comes from an older cli/compiler/typescript version but how can I determine the real problem?

If I start to update cli and others that's a disaster because I couldn't stop updateing Angular to 7.2 and that means a lot of code changes. (Tried that and gave up after one day.)

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
The file should had be included where the project was. Try to copy it from some angular example and try again. This file is needed for the cli. CLI 6.0+ don't need this file yes. - Swoox
I'he added the file and now having other errors. With older compiler-cli and typescript I get a length of undefined error. If I update to newer compiler-cli and typescript it throws the Versions of @angular/compiler-cli and typescript could not be determined. error again so I'm at the beginning again. - Perrier
I seen the answer to try npm install -g [email protected] - Swoox

1 Answers

0
votes

After reading some issues reported on the GitHub repository, I found the solution.

In order to update the angular-cli package installed globally in your system, you need to run:

npm uninstall -g angular-cli npm cache clean or npm cache verify (if npm > 5) npm install -g @angular/cli@latest Depending on your system, you may need to prefix the above commands with sudo.

Also, most likely you want to also update your local project version, because inside your project directory it will be selected with higher priority than the global one:

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