angular-cli: ERROR in Error encountered resolving symbol values statically. Calling function 'PerfectScrollbarModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function
Please provide us with the following information:
OS?
Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Mac OSX
Versions.
Please run
ng --version
. If there’s nothing outputted, please run in a Terminal:node --version
and paste the result here: cli beta 24
Repro steps.
Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.
- generate new project with cli beta 24
- npm install angular2-perfect-scrollbar --save
- import PerfectScrollbarModule.forRoot({suppressScrollX: true})
The log given by the failure.
Normally this include a stack trace and some more information.
ERROR in Error encountered resolving symbol values statically. Calling function ‘PerfectScrollbarModule’, function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /…/app.module.ts, resolving symbol AppModule in /…/src/app/app.module.ts
Mention any other details that might be useful.
angular version 2.3.1
Thanks! We’ll be in touch soon.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 65
- Comments: 98 (5 by maintainers)
Commits related to this issue
- Fix AOT compilation errors Providers and their functions need to be exported: https://github.com/angular/angular-cli/issues/3707#issuecomment-271499385 ngx-ui-switch replaces angular2-ui-switch with... — committed to azavea/climate-change-lab by deleted user 7 years ago
- Fix AOT compilation errors Providers and their functions need to be exported: https://github.com/angular/angular-cli/issues/3707#issuecomment-271499385 ngx-ui-switch replaces angular2-ui-switch with... — committed to azavea/climate-change-lab by deleted user 7 years ago
- fix aot compilation for packages, details can be found here: https://github.com/angular/angular-cli/issues/3707 — committed to SparksNetwork/sparks-ng2-frontend by emanuelvircaimprezzio 7 years ago
- Fixed loadChildren failing on ng build prod because of unsupported expression by webpack. see https://github.com/angular/angular-cli/issues/3707#issuecomment-311118242 — committed to vuvuzella/db-training-app by vuvuzella 7 years ago
- Fix Lambda Provider bug Issue with providing with lambda: https://github.com/angular/angular-cli/issues/3707 — committed to Bielik20/LazyForms by Bielik20 7 years ago
- Fix Lambda Provider bug Issue with providing with lambda: https://github.com/angular/angular-cli/issues/3707 — committed to Bielik20/LazyForms by Bielik20 7 years ago
please provide a link to your clear guidelines about publishing compatible library, I’m trying to make one and I’d like it to be compatible.
what’s exactly happening here?
We are working in the future to show a warning for those. I also think it shouldn’t be an error, but there are cases where an error can happen because of these libraries (routing for example) and these libraries are not AOT-compatible (at all!).
We have clear guidelines for libraries that include generating those files and what to publish to NPM. If libraries don’t follow those guidelines we can’t guarantee that they’ll be compatible.
And yes, we have report of these a lot, and when I tell the relation team they are actually efficient in dealing with those. So there’s hope.
I’m using @angular/cli beta30, and I have the same issue with ngx-translate. Similar error appears at the first time running
ng serve
, but compilation is successful after I just press Ctrl + S to a file again without changing anything, even so the translation works fine. Could be a bug of @angular/cli?@christianacca I’ve tried your app and I found something curious. Once you execute
ng serve
compilation it will fail, but if you doctrol+s
in any of your files, recompilation will trigger again and, boom, it will work. Why is this happening?? Honestly, I don’t have any clue yet. We’ll have to dig into it.This issue should not be closed as the error continues
I solved it by replace the anonymous (lambda) method to explicitly method:
providers: [ TranslateService, { provide: TranslateLoader, useFactory: translateLoader, deps: [Http] } ]
and following method:export function translateLoader(http: Http) { return new TranslateStaticLoader(http, 'assets/i18n', '.json');
instead of:
TranslateModule.forRoot({ provide: TranslateLoader, useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'), deps: [Http] })
This error is super strange. I have error upon
ng serve
in app.module.ts and after I make minor change (e.g. add whitespace or new line) compiler compiles the code successfully. Even if I revert the change the error is still gone…version: 1.0.0-rc.1
Same issue trying to use angular2-jwt (Json web tokens)
import { AUTH_PROVIDERS } from ‘angular2-jwt’;
Simply resolved by creating a factory like below one (my use case is to have custom HTTP provider hence adjust below code to your needs)
http.factory.ts
app.module.ts
package.json
Hope it will help someone!
Same here too! A problem with angular2-jwt
angular2-perfect-scrollbar is just one example , the are plenty modules like that. What you saying all of them will not be compatible with Angular CLI? What that means to us? We can not upgrade because of 3rd party modules simply will stop working. That is kind of odd path. Where would I find information about “publishing metadata” in context with CLI compatibility?
I was getting this error when trying to consume a component library that I’m developing locally in an Angular app that I’m also developing locally.
I was using
npm link
to create a symlink from the app to the component library. I had successfully compiled the library for AOT and was testing it out in the app. I got an error runningng build
in the app with a stacktrace that started with:It turns out that the problem wasn’t with my code. The issue is that the symlinked library contained its own
node_modules
directory. angular-cli was getting confused between thenode_modules
in the library (which theoretically shouldn’t be present in an AOT-compiled library) and thenode_modules
in the host app.I changed the name of
node_modules
in the library toNOT_node_modules
and the app compiled perfectly.I have the same problem, and when it re-compiles it goes away. How could this issue be closes ?
+1
I start using ng2-cli but why official Angular 2 core library will trigger this error? Very frustrated for switching to AoT after over 1 day of trying…
I am getting the same error, i tried to fix it by converting into an export function: Problem: {provide: APP_INITIALIZER, useFactory: (config: AppConfig) => () => config.load(), deps: [AppConfig], multi: true }, Step1: export function textFunction(config: AppConfig): any { () => { config.load() } }
{provide: APP_INITIALIZER, useFactory: textFunction, deps: [AppConfig], multi: true },
Error: AppInits[i] is not a function
Step2: export function textFunction(config: AppConfig) { return config.load(); } {provide: APP_INITIALIZER, useFactory: textFunction, deps: [AppConfig], multi: true },
Error: AppInits[i] is not a function
When i convert into an export function compiler error gets disappeared but the app breaks with appInits[i] is not a function. Can you please guide me how to convert appIntializer useFactory to an export method.
I have same issue. in beta.22 all work fine. but when I upgrade to beta.24 I got the following error:
ERROR in Error encountered resolving symbol values statically. Calling function 'SharedModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in ../src/app/app.module.ts, resolving symbol AppModule in ../src/app/app.module.ts
I’m was also getting this error when trying to create ngrx reducers using a function call:
Since reducers are just functions that pass in state/action, you can still export a function that wraps this constant:
Adds some verbosity, but at least it works with AoT.
Fixed by deleting
@angular
folder at internalnode_modules
directory of a problematic module (ng2-color-picker
in my case).I had the same issue @tom10271. I think your problem is different than op’s. Please check if you have a node_modules folder in ./src folder and if so remove it.
This article also goes into some detail on the sometimes frustrating interactions between ngrx/store. ngrx/effects, and AOT:
http://orizens.com/wp/topics/guidelines-for-developing-with-angular-ngrxstore-ngrxeffects-aot/
Check out this article as it helps clear up some of the confusion with regard to getting your code ready for AOT. Unfortunately it’s a necessary evil so the AOT compiler can do it’s job and as many are facing, libraries will need to be updated for full support.
Making your Angular 2 library statically analyzable for AoT
Additionally, AOT is on by default, so you can always set the flag
--aot false
when runningng build
if you don’t care about it and/or will refactor for AOT support at a later time.Fun fact, you’ll also get errors if you include a component/pipe/directive that isn’t part of a module. github issue. Not exactly an assumed behavior but I’m told an expected one.
Good Luck!
@loicsalou I just came across your comment. You can refer to this guide https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464#.9y88ipdk7 on how to make a working module.
I have the same issue with:
Error:
client?93b6:80Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 12:42 in the original .ts file), resolving symbol compose in /data/2017/search-project/node_modules/@ngrx/core/compose.d.ts, resolving symbol appStore in /data/2017/search-project/src/app/main/app.store.ts, resolving symbol appStore in /data/2017/search-project/src/app/main/app.store.ts, resolving symbol appStore in /data/2017/search-project/src/app/main/app.store.ts, resolving symbol AppModule in /data/2017/search-project/src/app/main/app.module.ts, resolving symbol AppModule in /data/2017/search-project/src/app/main/app.module.ts, resolving symbol AppModule in /data/2017/search-project/src/app/main/app.module.ts
Also getting this error, upgrading typescript seems to resolve it (although it might create other errors 😕)
This issue reappeared in version rc0. In a completely new project.
ERROR in Error encountered resolving symbol values statically. Calling function 'makeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol NgModule in E:/DocCenter/va_WorkStation_Benben/vaSites/upgrade-project/node_modules/@angular/platform-browser/node_modules/@angular/core/src/metadata/ng_module.d.ts, resolving symbol NgModule in E:/DocCenter/va_WorkStation_Benben/vaSites/upgrade-project/node_modules/@angular/platform-brows er/node_modules/@angular/core/src/metadata.d.ts, resolving symbol NgModule in E:/DocCenter/va_WorkStation_Benben/vaSites/upgrade-project/node_modules/@angular/platform-browse r/node_modules/@angular/core/src/core.d.ts, resolving symbol NgModule in E:/DocCenter/va_WorkStation_Benben/vaSites/upgrade-project/node_modules/@angular/platform-browser/node_modules/@angular/core/index.d.ts, resolving symbol BrowserModule in E:/DocCenter/va_W orkStation_Benben/vaSites/upgrade-project/node_modules/@angular/platform-browser/src/browser.d.ts, resolving symbol BrowserModule in E:/DocCenter/va_WorkStation_Benben/vaSites/upgrade-project/node_modules/@angular/platform-browser/src/browser.d.ts
Removing the .forRoot() on FlexLayoutModule fixed the problem
Had an issue with declaring a variable inside of a custom
forRoot
function I’ve createdTurned that variable into an exported const, and it solved the issue… for some reason, it doesn’t like variable declared inside of the
forRoot
functions.It also happens with
console.log
and other non exported function calls according to #17663Sorry I ment Angular CLI instead of AOT. But actually all of this problems are related to AOT somehow, since AOT compatible code resolves the issue…
@metodribic Why do I have this problem when using
ng serve
if it’s a problem with AoT?@Aides359 It’s better to use this approach for dynamic loading modules with AOT: Lazy loading module
Having the same problem the first time I make a ng serve, then I save a component and all is OK, ¿why?
And my app.module.ts pos 109 is:
(backend: XHRBackend, defaultOptions: RequestOptions, router:Router) => {
of the providers:Specifying paths to @angular inside AngularCLI’s tsconfig.json solved for me.
“paths”: { “@angular/*“: [“../node_modules/@angular/*“] }
I tried but it not working! How about I can set properly formatted for ahead of time compilation? I did read https://medium.com/@isaacplmann/getting-your-angular-2-library-ready-for-aot-90d1347bcad but I understant, what is metadata.json, ngFactory.ts? I see only I use forRoot() it have issue
I have the same issue when creating translation files using ng-xi18n
Error: 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,…
I get the same error with angular2-cool-storage Linux x64 npm@3.5.2 typescript@2.1.5 angular-cli@1.0.0-beta.26 angular2-cool-storage@1.2.2 Unfortunately, I see no lambda in imports statement:
import { CoolStorageModule } from 'angular2-cool-storage'; @NgModule({ imports: [CoolStorageModule], }) export class CoreModule {}
results in:ERROR in Error encountered resolving symbol values statically. Calling function 'makeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function,...
What I did to fix this issue was not using lambda in the function I was passing as parameter for
useFactory
. I usedfunction(){ return new Config() }
instead of() => new Config()
and it worked.I had this error (also disappearing after triggering recompile) with
and was able to resolve it by changing it to
However this seems to be more of a workaround than a proper solution.
I get this error when attempting to npm link to a local module control library
@PriNcee11 try to remove the arrow function with export function. Read the AOT guidelines in this article.
@tomaszczechowski Thanks! your solution worked for me!!
Same error in @angular/cli: 1.0.1
+1
for angular2-auth
on imports: [ … AuthModule.forRoot(), … ],
@davefedele my project is quite big, got a few people working on it. Is there a way to check this automatically or semi-automatically?
@jmcmichael I dealt with basically the same thing yesterday and was able to resolve it, see my comment here: https://github.com/ngrx/store/issues/348#issuecomment-285496328
In short, I created a service that adds the reducers to the store after the module compiles.
I’m getting this error with ngrx’s combineReducers function. An initial compile throws ‘Error encountered resolving symbol values statically. Calling function ‘combineReducers’, function calls are not supported.’
Prompting a recompile by updating a watched .ts file fires off a build that then succeeds w/o error.
Changing function reducer as the message suggests works for me, though it’s a weird error:
It was not working:
export const SearchResultReducer = (state: SearchResultState = INITIAL_SEARCH_RESULT_STATE, action: Action): SearchResultState => { ...};
This is working:
export function SearchResultReducer(state = INITIAL_SEARCH_RESULT_STATE, action: Action): SearchResultState { ... }
I have the same problem with the FlexLayoutModule. Can’t live with it and can’t live without it.