2017-07-28 118 views
0

當我嘗試運行ng serve 我得到這個錯誤:角Cli時NG服務不工作

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) 

我試圖卸載@角/ CLI並安裝@角/ CLI @最新並且我得到了相同的錯誤

回答

1

按照以下步驟從角度CLI開始。

首先更新節點版本:

  1. 因此,首先通過鍵入命令node -v檢查您的節點版本。
  2. 如果節點版本低於6.x.x,則更新它,因爲角度CLI需要節點版本高於6.x.x.要更新節點版本,請運行以下命令。

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

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

    然後運行命令:nvm use 7.10.0

  3. 這個運行命令npm install -g @angular/cli後安裝角CLI

  4. 然後ng new my-new-project創建新項目。
  5. 然後cd my-new-project去創建項目目錄裏面。
  6. 然後最後ng serve運行您的應用程序。

附加: 要更新您的角2項目轉變爲角4項目如下命令來運行:

* 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/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] 
        @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] 
        @angular/[email protected] @angular/ [email protected] @angular/[email protected] --save 
+0

正如一個供參考,以'@安裝next'現在將安裝5.0.0公測。如果你想堅持4.x.使用'@ latest'。 –