首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >示例webpack angular4应用程序抛出错误

示例webpack angular4应用程序抛出错误
EN

Stack Overflow用户
提问于 2017-04-12 06:17:25
回答 4查看 1.7K关注 0票数 1

我正在尝试创建一个安装在https://angular.io/docs/ts/latest/guide/webpack.html中的样例角webpack应用程序,但是它给我带来了大约26个错误。即使将打字本改为"~2.2.1",也会出现这些错误。

有人能帮我改正这些错误吗?

代码语言:javascript
复制
[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.
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-04-13 09:56:54

TSXXX错误似乎肯定与在2.1版本之前使用TypeScript有关,例如,这里这里

请核实:

  • 在您的TypeScript文件中声明的package.json版本("typescript":"~2.2.1“将可以)
  • 用于编译项目的TypeScript版本。您可以从npm命令的输出中验证这一点。您应该看到类似于此[at-loader] Using typescript@2.0.10 from typescript and "tsconfig.json" from /usr/src/ng2-projects/angular-webpack/src/tsconfig.json的内容;typescript@部分将显示用于编译的版本。

TS2304错误似乎与所需类型声明的错误配置有关。有关如何配置它们的清晰说明,请参见这里

票数 5
EN

Stack Overflow用户

发布于 2017-04-16 20:57:05

我也遇到了这个问题。在花了两天的时间后,在一些帮助下,我能够让它开始工作。事实上,我不能完全归功于修复,其他人确实帮了很多忙。

  1. 检查系统上安装的类型记录版本。
  2. 比较一下package.json中的版本。

我不记得是否更新了打字本,但当时是2.2.2,所以我更新了package.json,以反映安装在我的系统上的版本。

为我工作过。

票数 1
EN

Stack Overflow用户

发布于 2017-06-20 14:39:34

也许这会对某些人有所帮助:我在打字方面有很多不同的错误。我把我的tsconfig.json移到根文件夹,错误消失了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43361702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档