2017-04-12 71 views
1

我想創建一個示例angular-webpack應用程序在https://angular.io/docs/ts/latest/guide/webpack.html中指定,但它拋出了大約26個錯誤。即使在將打字稿版本更改爲「〜2.2.1」之後,這些錯誤即將到來。示例webpack angular4應用程序拋出錯誤

任何人都可以幫助我解決這些錯誤嗎?

[at-loader] Checking finished with 26 errors                  chunk {0} vendor.js 
(vendor) 2.64 MB {2} [initial] [rendered] 
chunk {1} app.js, app.css (app) 3.57 kB {0} [initial] [rendered] 
chunk {2} polyfills.js (polyfills) 577 kB [entry] [rendered] 

WARNING in ./~/@angular/core/@angular/core.es5.js 
5870:15-36 Critical dependency: the request of a dependency is an expression 

WARNING in ./~/@angular/core/@angular/core.es5.js 
5886:15-102 Critical dependency: the request of a dependency is an expression 

ERROR in [at-loader] ./node_modules/@angular/common/src/platform_id.d.ts:8:42 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/common/src/platform_id.d.ts:9:41 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/common/src/platform_id.d.ts:10:45 
    TS1039: Initializers are not allowed in ambient contexts. 
ERROR in [at-loader] ./node_modules/@angular/common/src/platform_id.d.ts:11:44 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/compiler/src/util.d.ts:8:36 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/core/src/animation/animation_metadata_wrapped.d.ts:12:33 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/core/src/animation/dsl.d.ts:34:33 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/core/src/errors.d.ts:9:33 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/core/src/errors.d.ts:10:43 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/core/src/errors.d.ts:11:42 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/core/src/errors.d.ts:12:43 
    TS1039: Initializers are not allowed in ambient contexts. 
ERROR in [at-loader] ./node_modules/@angular/core/src/errors.d.ts:13:35 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/core/testing/src/before_each.d.ts:1:59 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/http/src/backends/browser_jsonp.d.ts:1:33 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/platform-browser/src/dom/dom_renderer.d.ts:14:41 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./node_modules/@angular/router/src/shared.d.ts:15:37 
    TS1039: Initializers are not allowed in ambient contexts. 

ERROR in [at-loader] ./src/app/app.component.spec.ts:3:1 
    TS2304: Cannot find name 'describe'. 

ERROR in [at-loader] ./src/app/app.component.spec.ts:4:3 
    TS2304: Cannot find name 'beforeEach'. 

ERROR in [at-loader] ./src/app/app.component.spec.ts:7:3 
    TS2304: Cannot find name 'it'. 

ERROR in [at-loader] ./src/app/app.component.spec.ts:9:5 
    TS2304: Cannot find name 'expect'. 

ERROR in [at-loader] ./src/app/app.component.ts:5:13 
    TS2304: Cannot find name 'require'. 

ERROR in [at-loader] ./src/app/app.component.ts:6:12 
    TS2304: Cannot find name 'require'. 

ERROR in [at-loader] ./src/main.ts:4:5 
    TS2304: Cannot find name 'process'. 

ERROR in [at-loader] ./src/polyfills.ts:3:1 
    TS2304: Cannot find name 'require'. 

ERROR in [at-loader] ./src/polyfills.ts:5:5 
    TS2304: Cannot find name 'process'. 

ERROR in [at-loader] ./src/polyfills.ts:10:3 
    TS2304: Cannot find name 'require'. 
Child html-webpack-plugin for "index.html": 
    chunk {0} index.html 325 bytes [entry] [rendered] 
Child extract-text-webpack-plugin: 
    chunk {0} extract-text-webpack-plugin-output-filename 1.92 kB [entry] [rendered] 
webpack: Failed to compile. 

回答

4

的TSXXX錯誤似乎肯定涉及到使用打字稿之前的2.1版本,例如herehere解釋 。

請驗證:

  • 在你聲明的打字稿版本的package.json文件(「打字稿」:「〜2.2.1」將是OK)
  • 您有效地利用到打字稿版本編譯該項目。您可以從npm start命令的輸出中驗證。你應該看到類似[at-loader] Using [email protected] from typescript and "tsconfig.json" from /usr/src/ng2-projects/angular-webpack/src/tsconfig.json; [email protected]部分將顯示用於編譯的版本。

TS2304錯誤似乎與所需類型聲明的配置錯誤有關。請參閱here瞭解如何配置它們。

0

我有同樣的問題。我更改爲typescript 2.3(package.json中的「typescript」:「〜2.3」),現在我再也不會看到這些錯誤了。

1

我遇到了這個問題,以及..花了2天后,有一些幫助,我能夠得到它的工作。事實上,我不能完全相信修復,其他人確實幫了很大忙。

  1. 檢查安裝在系統上的打字稿版本。
  2. 比較你在package.json中的版本。

我不記得是否我更新打字稿或不是,但當時它是2.2.2所以我更新了package.json以反映安裝在我係統上的版本。

爲我工作。

1

也許它會幫助別人: 我有很多關於打字稿的不同錯誤。我將我的tsconfig.json移動到根文件夾並且錯誤消失了。

相關問題