angularangular-cli

'ng serve' does not work after a double install


I used to have Angular CLI, but I mistakenly installed it again with

npm install -g angular-cli

And now when I run ng serve it complains:

It seems like you're using a project generated using an old version of the Angular CLI.

The latest CLI now uses webpack and includes a lot of improvements, include a simpler workflow, a faster build and smaller bundles.

To get more info, including a step-by-step guide to upgrade the CLI, follow this link: https://github.com/angular/angular-cli/wiki/Upgrading-from-Beta.10-to-Beta.12

When I try to create a new project using ng new in another directory, it complains that:

Cannot find module 'reflect-metadata'

So what is the problem?


Solution

  • The key is to have both global and local Angular-cli versions the same.

    Let's say we want to fixate it to eg. 1.0.0-beta.15.

    So you can try to fixate the version in npm install -g angular-cli@1.0.0-beta.15 and in your package.json fixate it to the same version: "angular-cli": "1.0.0-beta.15". Then run npm install --save-dev.

    Currently Angular CLI can be found on NPM under @angular/cli instead of angular-cli. Here are links to documentation how to uninstall old and install the latest version of CLI.