简体   繁体   中英

Angular Cli ng serve don't work

When I try to run ng serve I got this error :

The "@angular/compiler-cli" package was not properly installed. Error: 
TypeError
: Object prototype may only be an Object or null: undefined
Error: The "@angular/compiler-cli" package was not properly installed. 
Error: Ty
peError: Object prototype may only be an Object or null: undefined
at Object.<anonymous> (C:\Users\Mounadi\angular2-quickstart\node_modules\@ng
tools\webpack\src\index.js:14:11)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Mounadi\angular2-quickstart\node_modules\@an
gular\cli\tasks\eject.js:10:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)

I tried to uninstall @angular/cli and install @angular/cli@latest and I got the same error

Follow the below steps to start with angular CLI.

First update node version:

  1. So, first check your node version by typing command node -v .
  2. If node version is lower than 6.xx then update it because angular CLI requires node version to be higher than 6.xx To update node version run the below command.

    nvm install <new version> --reinstall-packages-from=<old version>

    Ex: nvm install 7.10.0 --reinstall-packages-from=5.1.0

    Then run command: nvm use 7.10.0

  3. After this run command npm install -g @angular/cli to install Angular CLI .

  4. Then ng new my-new-project to create new project.
  5. Then cd my-new-project to go inside created project directory.
  6. And then finally ng serve to run your app.

Extra: To update your angular 2 project into angular 4 project run below command:

    * On Linux/Mac: npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-    
                     server,router,animations}@next --save server,router,animations}@next --save

     * On Windows: npm install @angular/common@next @angular/compiler@next @angular/compiler-cli@next @angular/core@next 
                   @angular/forms@next @angular/http@next @angular/platform-browser@next @angular/platform-browser-dynamic@next 
                   @angular/platform-server@next @angular/  router@next @angular/animations@next --save

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM