Angular2 CLI 构建生产环境错误:调用函数 'NoOpAnimationDriver',不支持函数调用。

4
当我切换到使用@angular 2.4.4时,我开始收到下面的错误。当我回滚到@angular 2.2.1时,我可以毫无问题地构建。
在使用angular 2.4.4时,我仍然可以使用“npm start”在本地运行我的程序。
只有当我尝试使用“ng build --prod --aot”运行构建时,我才会收到错误。
据我所知,我没有使用“NoOpAnimationDriver”或“BrowserTestingModule”,这两个都在错误中被引用。
我希望有人之前见过这个错误,并可能告诉我以下任何一点: 1.错误实际上在说什么。 2.为什么我在不使用的函数中出现了错误。 3.我如何能够修复错误。 4.我可以在哪里查找更多关于理解这些错误的信息。
ERROR in Error encountered resolving symbol values statically. Calling function 'NoOpAnimationDriver', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AnimationDriver.NOOP in c:/Development/SentriKeyApp/node_modules/@angular/platform-browser/src/dom/animation_driver.d.ts, resolving symbol BrowserTestingModule in c:/Development/SentriKeyApp/node_modules/@angular/platform-browser/testing/browser.d.ts, resolving symbol BrowserTestingModule in c:/Development/SentriKeyApp/node_modules/@angular/platform-browser/testing/browser.d.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'c:\Development\SentriKeyApp\src'
 @ ./src/main.ts 4:0-74
 @ multi main

ERROR in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
Module not found: Error: Can't resolve 'c:\Development\SentriKeyApp\src\$$_gendir' in 'c:\Development\SentriKeyApp\node_modules\@angular\core\src\linker'
 @ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js 71:15-36 87:15-102
 @ ./~/@angular/core/src/linker.js
 @ ./~/@angular/core/src/core.js
 @ ./~/@angular/core/index.js
 @ ./src/main.ts
 @ multi main

你正在使用哪个版本的 angular-cli - shusson
现在我正在使用1.0.0-beta.26版本。在那之前,我使用的是1.0.0-beta.21版本。 - Jesse Y
过去我遇到过类似的错误,当时是因为库版本与 angular-cli 默认版本不匹配。尝试使用 ng init 创建一个新项目,并将其 package.json 与你的项目进行比较。 - shusson
3个回答

1

ng build --prod 命令也会调用 --aot,看起来问题与此有关。

尝试运行 ng build --prod --aot false 以避免 Ahead-of-Time 编译。


1
以下错误是一个预编译器错误。
错误:静态解析符号值时遇到错误。调用函数“declarations”,不支持函数调用。考虑将该函数或lambda替换为对导出函数的引用。 Before:
const declarations = () => [
  SomeComponent
];
@NgModule({
  declarations: declarations(),
})
export class SomeModule {}

之后:
export function declarations() {
  return [
    SomeComponent
  ];
}
@NgModule({
  declarations: declarations(),
})
export class SomeModule {}

https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.let72omre

使用ng build时加上-prod现在默认使用预编译器(Ahead of Time compiler)。自beta.28版本以来就已经生效。请参见此处:

https://github.com/angular/angular-cli/blob/master/CHANGELOG.md


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接