出现以下错误:错误:内部错误:未知标识符{}

时间:2019-12-12 16:23:39

标签: angular

im正在开发角度应用程序。在开发过程中一切正常,但是当我想使用以下方式构建生产版本时:

ng build --prod --aot

我遇到以下错误:

> ng build --prod --aot

Browserslist: caniuse-lite is outdated. Please run next command `npm update`

Date: 2019-12-12T16:15:13.967Z
Hash: 3d59c47f3fb49f8e51cf
Time: 28553ms
chunk {0} runtime.741402d1d47331ce975c.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main.4af9b61479361f268d39.js (main) 128 bytes [initial] [rendered]
chunk {2} polyfills.d64fff5b0a45205ed7b5.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} polyfills-es5.cae7692ec3ddfa1785ab.js (polyfills-es5) 68.1 kB [initial] [rendered]
chunk {4} styles.b944be682ec3583295e3.css (styles) 351 kB [initial] [rendered]

ERROR in : Error: Internal error: unknown identifier {}
    at Object.importExpr$1 [as importExpr] (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:25070:27)
    at tokenExpr (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:21548:43)
    at depDef (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:21554:76)
    at /Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:21544:68
    at Array.map (<anonymous>)
    at singleProviderDef (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:21544:40)
    at providerDef (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:21470:13)
    at /Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:21644:81
    at Array.map (<anonymous>)
    at NgModuleCompiler.compile (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:21644:48)
    at AotCompiler._compileModule (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:25015:36)
    at /Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:24934:70
    at Array.forEach (<anonymous>)
    at AotCompiler._compileImplFile (/Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:24934:23)
    at /Users/ilem0n/Projekte/Private/NGBudgetManager/frontend/node_modules/@angular/compiler/bundles/compiler.umd.js:24924:74
    at Array.map (<anonymous>)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ng-budget@1.0.0 build:prod: `ng build --prod --aot`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ng-budget@1.0.0 build:prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ilem0n/.npm/_logs/2019-12-12T16_15_14_106Z-debug.log

Process finished with exit code 1

我的配置:

Angular CLI: 8.3.20
Node: 12.10.0
OS: darwin x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.20
@angular-devkit/build-angular     0.803.20
@angular-devkit/build-optimizer   0.803.20
@angular-devkit/build-webpack     0.803.20
@angular-devkit/core              8.3.20
@angular-devkit/schematics        8.3.20
@angular/cdk                      8.2.3
@angular/cli                      8.3.20
@angular/flex-layout              8.0.0-beta.27
@angular/http                     8.0.0-beta.10
@angular/material                 8.2.3
@ngtools/webpack                  8.3.20
@schematics/angular               8.3.20
@schematics/update                0.803.20
rxjs                              6.5.3
typescript                        3.5.3
webpack                           4.39.2

我在网上发现了一些类似的问题,但是没有一个问题对我有帮助。 我在网上发现的东西

Angular Compiler throws Internal error: unknown identifier {}

ERROR in : Error: Internal error: unknown identifier []" when running ng build --prod

我没有可注入的超类,并且我的项目中没有使用或导入OpaqueToken。

任何想法如何解决?

3 个答案:

答案 0 :(得分:2)

如果您使用 Window 作为提供程序,只需将其删除

  { provide: Window, useValue: window},

答案 1 :(得分:0)

弄清楚了:  在每个功能都导入的共享模块中,有以下一行:

providers: [
  { provide: MAT_DIALOG_DATA, useExisting: {} }
]

在我删除了这些内容之后,构建运行得很好。

答案 2 :(得分:0)

从组件的提供者列表中删除窗口对象

Collections