You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AoT error when provider specifies useFactory with inline function #13614
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
If a provider specifies an inline function/arrow function for useFactory, the build fails with the error 'Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function.'
Babel does have support for them, so I guess it's possible for typescript to as well. I'd suggest filing an issue with typescript and asking them to support function names of this type.
It works as expected - the function does indeed have a name.
Another thing worth mentioning is that even if the code is changed to fulfill the AoT requirements, it still chokes on third-party libs that have been pre-compiled with TypeScript. Case in point is https://github.com/auth0/angular2-jwt - I am attempting to use the exported AUTH_PROVIDERS in my providers. If I copy the source angular2-jwt.ts into my angular project and fix it so that useFactory has a name, everything works great. However, if I compile the source code, copy the resulting .d.ts and .js into node_modules/angular2-jwt, and import from there, it chokes with the same warning again, even though I supposedly fixed it and even though the emitted JavaScript contains the code useFactory: function useFactory(http, options)!
The weirdest thing is that this only started happening once I upgraded to angular-cli beta.24 and angular v2.4.0. Using angular-cli beta.22 and angular v2.2.3 there was no error.
Activity
DzmitryShylovich commentedon Dec 21, 2016
ngcdoesn't execute your code so it should be statically analyzable. Arrow/anonymous functions don't have a name.is equal to
this is why it works
DzmitryShylovich commentedon Dec 21, 2016
https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.3xvtag7g9
mischkl commentedon Dec 21, 2016
Interesting.. That explains why it doesn't work. But this is incorrect behavior according to ES6 spec: http://www.2ality.com/2015/09/function-names-es6.html?m=1
I don't know whether the problem lies with tsc or ngc but something isn't right here...
mattlewis92 commentedon Dec 22, 2016
Looking at the ES6 compat table, typescript doesn't seem to support them (I think it's

object methods (function)): https://kangax.github.io/compat-table/es6/#typescriptBabel does have support for them, so I guess it's possible for typescript to as well. I'd suggest filing an issue with typescript and asking them to support function names of this type.
mischkl commentedon Dec 22, 2016
@mattlewis92 thanks for that. However it doesn't seem to be purely TypeScript-related, since if I use tsc (v2.0.10) to compile the following code:
It works as expected - the function does indeed have a name.
Another thing worth mentioning is that even if the code is changed to fulfill the AoT requirements, it still chokes on third-party libs that have been pre-compiled with TypeScript. Case in point is https://github.com/auth0/angular2-jwt - I am attempting to use the exported AUTH_PROVIDERS in my providers. If I copy the source
angular2-jwt.tsinto my angular project and fix it so thatuseFactoryhas a name, everything works great. However, if I compile the source code, copy the resulting.d.tsand.jsintonode_modules/angular2-jwt, and import from there, it chokes with the same warning again, even though I supposedly fixed it and even though the emitted JavaScript contains the codeuseFactory: function useFactory(http, options)!The weirdest thing is that this only started happening once I upgraded to angular-cli beta.24 and angular v2.4.0. Using angular-cli beta.22 and angular v2.2.3 there was no error.
mattlewis92 commentedon Dec 22, 2016
That's really odd, it does seem that there have been a few internal changes that have inadvertently been breaking in 2.4
kemsky commentedon Jan 9, 2017
Any code that is referenced and uses static initialization is broken:
However, referencing using
Test['field']does not trigger error and app works (but may broke if mangled).I'm loosing a lot of time with this stuff.
partially fix for angular/angular#13614
jpduckwo commentedon Jul 26, 2017
I'm running into this problem. For those using webpack AOT compilation the error message is the generic:
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'Updating useFactory as above fixed it for me
WillHall commentedon Dec 10, 2019
I was stuck on this issue for a while, so I figured I would just share what I did to get around it.
Functions are not supported in decorators error in loadChildren solution.
Normal Way:
Becomes:
HTH googlers like me.
JoostK commentedon Mar 15, 2020
Support for this was added in #18390. Moreover, the Ivy compiler works a bit differently so that this is no longer an issue.
angular-automatic-lock-bot commentedon Apr 15, 2020
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.