2017-02-08 29 views
0

我嘗試過npm update,npm start然後安裝,但是在加載應用程序本身開始時出現錯誤。當我運行「npm start」時,在正常的Angular 2項目中出現「SyntaxError:意外的令牌導入」

它如何不能識別「導入」,正常標準引導文件的第一個字?

堆棧跟蹤是:

C:\Users\Andreas\Project>npm start 

> [email protected] start C:\Users\Andreas\Project 
> node ./app/main.ts 

C:\Users\Andreas\Project\app\main.ts:1 
(function (exports, require, module, __filename, __dirname) { import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 
                   ^^^^^^ 
SyntaxError: Unexpected token import 
    at Object.exports.runInThisContext (vm.js:76:16) 
    at Module._compile (module.js:542:28) 
    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.runMain (module.js:604:10) 
    at run (bootstrap_node.js:394:7) 
    at startup (bootstrap_node.js:149:9) 
    at bootstrap_node.js:509:3 

npm ERR! Windows_NT 10.0.14393 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" 
npm ERR! node v6.9.4 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] start: `node ./app/main.ts` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node ./app/main.ts'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the angular-quickstart package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node ./app/main.ts 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs angular-quickstart 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls angular-quickstart 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\Users\Andreas\Project\npm-debug.log 

C:\Users\Andreas\Project>npm start 

> [email protected] start C:\Users\Andreas\Project 
> node ./app/main.ts 

C:\Users\Andreas\Project\app\main.ts:1 
(function (exports, require, module, __filename, __dirname) { import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 
                   ^^^^^^ 
SyntaxError: Unexpected token import 
    at Object.exports.runInThisContext (vm.js:76:16) 
    at Module._compile (module.js:542:28) 
    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.runMain (module.js:604:10) 
    at run (bootstrap_node.js:394:7) 
    at startup (bootstrap_node.js:149:9) 
    at bootstrap_node.js:509:3 

npm ERR! Windows_NT 10.0.14393 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" 
npm ERR! node v6.9.4 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] start: `node ./app/main.ts` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node ./app/main.ts'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the angular-quickstart package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node ./app/main.ts 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs angular-quickstart 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls angular-quickstart 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\Users\Andreas\Project\npm-debug.log 
+0

您試圖啓動angular main.ts文件,該文件應該被轉換爲JavaScript,捆綁,由瀏覽器下載並由瀏覽器執行,並使用節點(這是一個服務器端JavaScript執行環境)。這沒有意義。你在哪裏讀過你需要執行這個命令? –

+0

要運行本地調試版本,在項目中運行「npm start」?這應該啓動服務器?我在這裏閱讀:https://angular.io/docs/ts/latest/guide/setup.html –

+0

下面是你的package.json文件應該看起來像如果你按照說明:https://github.com/angular /quickstart/blob/master/package.json。我猜這看起來不像那樣。 –

回答

0

角已經更新了它的結構,所以現在,很多事情都是一個「src」目錄中。

這使npm感到困惑,所以我不得不根據更新的「快速啓動項目」的新結構進行重組。一些遷移是必需的,但基本上我只是將代碼文件移動到適當的位置。

這是一個糟糕的過程,有一個糟糕的錯誤信息來指導。但我猜Angular 2相當不錯,更好的結構不會受到傷害。

相關問題