I am following the solution here of using the JitCompilerFactory
to load the runtime compiler and custom decorators to preserve the component and module metadata. But with the angular-cli --build-optimizer
flag I get:
ERROR Error: Cannot resolve all parameters for 'Parser'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Parser' is decorated with Injectable.
Here is my minimal reproduction, run ng serve --aot --build-optimizer
. As a control ng serve --aot
works.
If you use option
--build-optimizer
then@angular-devkit/build-optimizer/webpack-loader
loader is added to webpack loaders list.@angular-devkit/build-optimizer/webpack-loader
removesctorParameters
definitions from types that is not part ofplatformWhitelist
(source):I think that's correct behavior.
To work around it you could initialize
ctorParameters
manually beforeJitCompilerFactory
is created:And it seems to be risky as compiler is subject to internal changes. It works for
@angular/compiler@4.4.5
but may not work for other releases.