Angular2 CLI Build Prod错误:调用函数'NoOpAnimationDriver',不支持函数调用

时间:2017-01-23 21:26:15

标签: angular angular-cli

当我切换到使用@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

3 个答案:

答案 0 :(得分:1)

以下错误是提前编译错误。

  

错误:静态解析符号值时出错。调用   函数'声明',不支持函数调用。考虑   使用对导出的引用替换函数或lambda   功能

之前:

        <!DOCTYPE html>
    <html>
    <body>
    
    <img id="light" src="Red.png">
    
    <script>
    var list= ['https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/daemons.png',
    'https://img.clipartfox.com/837fed127e3383c2a61cf08f76a65081_pics-for-stop-light-yellow-clipart-traffic-light-yellow_641-880.png', 
    'http://previews.123rf.com/images/blojfo/blojfo1003/blojfo100300021/6559248-Traffic-light-with-red-light-Stock-Photo.jpg']; 
    var i = 0;
    function lightsCycle() {
        
        i = (i < list.length - 1) ? ++i : 0;
        
        document.getElementById("light").src = list[i];
    }
    
    </script> 
    
    <img id="light" src="https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/daemons.png">
    <button type = "button" onclick="lightsCycle()">Next Light</button>
    
    </body>
    </html>

<强>后:

const declarations = () => [
  SomeComponent
];
@NgModule({
  declarations: declarations(),
})
export class SomeModule {}

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

现在使用export function declarations() { return [ SomeComponent ]; } @NgModule({ declarations: declarations(), }) export class SomeModule {} -prod默认使用Ahead of Time编译器。这是自beta.28起生效的。见这里:

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

答案 1 :(得分:1)

ng build --prod也会调用--aot,看起来问题与之相关。

尝试运行ng build --prod --aot false以避免提前编译

答案 2 :(得分:0)

看到那个博客,你会找到答案 Getting your angular 2 ready for aotthis