2016-05-23 145 views
0

在運行「故宮開始」,我收到以下錯誤:在運行將輸出文件,而不是JavaScript文件過程中發生NPM啓動錯誤2

app/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'. 
    app/main.ts(1,30): error TS2307: Cannot find module '@angular/platform-browser-dynamic'. 

npm ERR! weird error 2 

npm WARN This failure might be due to the use of legacy binary "node" 

npm WARN For further explanations, please read 
/usr/share/doc/nodejs/README.Debian 

錯誤。我甚至嘗試了以下兩條命令:

sudo apt-get install nodejs-legacy 


sudo npm update -g && sudo npm install -g concurrently lite-server typescript 

但仍然錯誤仍然存​​在。該怎麼辦? 我使用的是Ubuntu 14.04操作系統。節點版本:6.2.0,nodejs:0.10.25並且在Angular2上工作。

+0

你能提供你的'package.json'和'tsconfig.json'文件的內容嗎?謝謝! –

+0

您是否在項目目錄中執行了'npm install'(而不是'-g'或其他)? – CherryDT

+0

@CherryDT是的。它沒有奏效。然後我嘗試了'sudo npm install',它對我很有用。但仍然爲什麼它的工作,我不知道。 – hithard

回答

0

而不是使用:npm install。 使用:sudo npm install在同一個目錄下,爲我工作。

您還可以:sudo npm install -g將其安裝到全球。 但是,請記住要在系統中安裝最新的nodejs。 希望有所幫助。

不要忘記使用angular2庫。

爲了消除,以下錯誤: app/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'. app/main.ts(1,30): error TS2307: Cannot find module '@angular/platform-browser-dynamic'.

務必: npm install angular2 --save

,並替代進口:

import {Component} from 'angular2/core'; import {bootstrap} from 'angular2/platform/browser'; 希望它helps.If不一定做評論。

+0

Angular2包裝聲明已從RC1中的'angular2'更改爲'@angular' – shershen