Angular 2 生产构建错误。在开发中工作正常

Posted

技术标签:

【中文标题】Angular 2 生产构建错误。在开发中工作正常【英文标题】:Angular 2 production build error. working fine in development 【发布时间】:2018-01-03 10:05:59 【问题描述】:

我可以在开发中运行以下命令,但是当我部署到生产环境时出现以下错误:

node_modules/@angular/common/src/pipes/async_pipe.d.ts(39,38): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/directive_normalizer.d.ts(19,100): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/directive_normalizer.d.ts(21,74): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/offline_compiler.d.ts(31,124): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/resource_loader.d.ts(13,23): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/runtime_compiler.d.ts(40,49): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/runtime_compiler.d.ts(42,65): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/util.d.ts(35,18): error TS2304: Cannot find name 'Promise'. node_modules/@angular/compiler/src/util.d.ts(36,46): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/application_init.d.ts(16,18): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/application_ref.d.ts(106,67): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/application_ref.d.ts(122,101): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/application_ref.d.ts(148,67): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/application_ref.d.ts(150,101): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/facade/lang.d.ts(12,17): error TS2693: 'Map' only refers to a type, but is being used as a value here. node_modules/@angular/core/src/facade/lang.d.ts(13,17): error TS2693: 'Set' only refers to a type, but is being used as a value here. node_modules/@angular/core/src/linker/compiler.d.ts(53,49): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/linker/compiler.d.ts(61,65): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/linker/ng_module_factory_loader.d.ts(14,34): error TS2304: Cannot find name 'Promise'. node_modules/@angular/core/src/linker/system_js_ng_module_factory_loader.d.ts(28,25): error TS2304: Cannot find name 'Promise'. node_modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl.d.ts(10,23): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/config.d.ts(279,62): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/interfaces.d.ts(78,99): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/interfaces.d.ts(157,109): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/interfaces.d.ts(227,115): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/interfaces.d.ts(297,91): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/interfaces.d.ts(367,50): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/router.d.ts(386,70): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/router.d.ts(408,59): error TS2304: Cannot find name 'Promise'. node_modules/@angular/router/src/utils/collection.d.ts(35,58): error TS2304: Cannot find name 'Promise'. node_modules/@types/core-js/index.d.ts(47,36): error TS2304: Cannot find name 'Iterable'. node_modules/@types/core-js/index.d.ts(353,48): error TS2304: Cannot find name 'PropertyKey'. node_modules/@types/core-js/index.d.ts(354,52): error TS2304: Cannot find name 'PropertyKey'. node_modules/@types/core-js/index.d.ts(355,34): error TS2304: Cannot find name 'PropertyKey'. node_modules/@types/core-js/index.d.ts(356,34): error TS2304: Cannot find name 'PropertyKey'.

【问题讨论】:

这发生在我使用 Visual Studio Web 部署。我的应用程序在我的本地环境中构建良好,但随后出现了 Iterable 和 PropertyKey 类型不存在的各种问题。 【参考方案1】:

所有这些错误都是打字稿编译器错误。在您的tsconfig.json 中添加"skipLibCheck": truecompilerOptions

【讨论】:

未捕获的错误:在 bundle.min.js 中由模块“t”导入了意外的值“[object Object]”。我在构建 @Rama 后收到此错误 抱歉@ram1405,如果不查看您的代码就很难诊断。 我可以有你的 gmail 或任何其他联系方式 任何关于蜜蜂的想法 对不起,我不知道那个错误是什么。您可以编辑您的问题以发布您的代码或创建一个 plunker。

以上是关于Angular 2 生产构建错误。在开发中工作正常的主要内容,如果未能解决你的问题,请参考以下文章

NextJS:生产中未定义的上下文值(在开发中工作正常)

科尔多瓦 ios 构建错误 65,但在 Xcode 中工作正常

窗口在构建时不呈现,在开发服务器中工作正常

React API 调用在开发中工作,在生产构建中失败

vuex 商店在开发服务器中工作,但在生产构建中不工作

NuxtJS:在开发中工作但在生产中工作的路由(netlify)