开发者问题收集

错误:错误:内部错误:未知标识符 {}

2019-12-12
2939

我正在开发一个 Angular 应用。开发过程中一切都运行良好,但当我想使用以下命令构建生产版本时:

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! [email protected] build:prod: `ng build --prod --aot`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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 抛出内部错误:未知标识符 {

运行 ng build --prod 时出现错误:错误:内部错误:未知标识符 []"

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

有什么想法可以解决这个问题吗?

3个回答

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

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

删除这些后,构建运行良好。

Peter C. Glade
2019-12-14

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

  { provide: Window, useValue: window},
naib khan
2021-03-09

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

@Component({
  selector: 'app-hello',
  templateUrl: './hello.component.html',
  styleUrls: ['./hello.component.scss'],
  // providers: [
  //   { provide: Window, useValue: window }
  // ]
})
Mustafa Omran
2021-03-11