angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open Oleg1969 opened this issue 9 years ago • 98 comments

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.

  1. generate new project with cli beta 24
  2. npm install angular2-perfect-scrollbar --save
  3. 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.

Oleg1969 avatar Dec 22 '16 16:12 Oleg1969

@haisaco If your code isn't properly formatted for ahead of time compilation - you will see errors like this. please see https://medium.com/@isaacplmann/getting-your-angular-2-library-ready-for-aot-90d1347bcad blog post to prepare you logic for aot.

looks like you need to export the variable tenantRoutes on its declaration

it may need to look something like thisexport_ const tenantRoutes: Routes = [ ... ]

efreethy-revprep avatar Apr 13 '17 15:04 efreethy-revprep

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

haisaco avatar Apr 14 '17 02:04 haisaco

+1

for angular2-auth

on imports: [ ... AuthModule.forRoot(), ... ],

GHakopian avatar Apr 17 '17 16:04 GHakopian

I got the same issue at angular-router (app-routing.module) using

@angular/cli: local (v1.0.0) node: 7.4.0 os: darwin x64 @angular/animations: 4.0.3 @angular/common: 4.0.3 @angular/compiler: 4.0.3 @angular/core: 4.0.3 @angular/forms: 4.0.3 @angular/http: 4.0.3 @angular/material: 2.0.0-beta.1 @angular/platform-browser: 4.0.3 @angular/platform-browser-dynamic: 4.0.3 @angular/router: 4.0.3 @angular/cli: 1.0.0 @angular/compiler-cli: 4.0.3

error: ERROR in Error encountered resolving symbol values statically. Reference to a local (non-exported) symbol 'routes'.

this error occurs, when I use variables from routing-params.ts inside my app-routing module:

  { component: CatListComponent, path: ''},
  { component: CatListComponent, path: 'cats' },
  { component: CatListComponent, path: `cats/:${ids.cats}` },
  { component: CatDetailComponent, path: `cats/:${ids.cats}/categ1/:${ids.categ1}` },
];```


if I change to the parameters directly which are available under `ids`, the error is gone:

```const routes: Routes = [
  { component: CatListComponent, path: ''},
  { component: CatListComponent, path: 'cats' },
  { component: CatListComponent, path: `cats/:catsUid` },
  { component: CatDetailComponent, path: `cats/:catsUid/categ1/:categ1Uid` },
];`

ankeknicker avatar Apr 25 '17 07:04 ankeknicker

I'm was also getting this error when trying to create ngrx reducers using a function call:

export const reducer = createReducer();

Since reducers are just functions that pass in state/action, you can still export a function that wraps this constant:

const reducerFn = createReducer();
export function reducer(state, action) {
  return reducerFn(state, action);
}

Adds some verbosity, but at least it works with AoT.

ajcrites avatar Apr 27 '17 14:04 ajcrites

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 running ng build in the app with a stacktrace that started with:

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 /my-angular-app/node_modules/my-
component/node_modules/@angular/core/core.d.ts ...

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 the node_modules in the library (which theoretically shouldn't be present in an AOT-compiled library) and the node_modules in the host app.

I changed the name of node_modules in the library to NOT_node_modules and the app compiled perfectly.

jeradg avatar May 06 '17 03:05 jeradg

Please update to latest version of angular2-perfect-scrollbar #2.0.6

I had the same issue after upgrade to 2.0.6 , Its working for me

https://www.npmjs.com/package/angular2-perfect-scrollbar

annaimaha avatar May 11 '17 07:05 annaimaha

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

import { XHRBackend, RequestOptions } from '@angular/http';
import { CookieService } from 'ng2-cookies';

import { HttpService } from './http.service';

export function HttpFactory(backend: XHRBackend, options: RequestOptions) {
  return new HttpService(backend, options);
}

app.module.ts

(...)
providers:
 [
    {
      provide: HttpService,
      useFactory: HttpFactory,
      deps: [ XHRBackend, RequestOptions ]
    }
 ]
(...)

package.json

(...)
"dependencies": {
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
 },
(...)

Hope it will help someone!

tomaszczechowski avatar May 14 '17 08:05 tomaszczechowski

I'm was getting this error on ubuntu14 but it's ok on ubuntu16 i'think my enviroment is broken. so i full install it....

anchorHanme avatar May 18 '17 03:05 anchorHanme

Same error in @angular/cli: 1.0.1

achieverprince avatar May 31 '17 10:05 achieverprince

Error still happens in cli version 1.1.0. As others have said, when serving, the first time it will throw an error, but changing a file will make it work for consequent builds. This obviously breaks building your project with aot or prod flag on.

borislemke avatar Jun 02 '17 05:06 borislemke

Since this issue was opened and closed several times in the past I think this error is not a bug in the CLI, but for sake of simplicity and debugging it could provide some more information so you would have at least some information where exactly the error occurs (and potentially how to resolve it).

metodribic avatar Jun 02 '17 06:06 metodribic

I am building Ionic3 app, I am having this error as in @jeradg error when I try to build/run the app.. I think it because I imported the angular SDK and used some of it's services that are built for the web application (using loopBack)...the folder for the mobile app is also added in the web app. I tried naming the outer node_module for the web app but still didn't work...Im not sure where is the problem.. any suggestion would be helpful ! thanx

YasirSherzad avatar Jun 05 '17 21:06 YasirSherzad

@tomaszczechowski Thanks! your solution worked for me!!

karthiks3000 avatar Jun 08 '17 13:06 karthiks3000

Specifying paths to @angular inside AngularCLI’s tsconfig.json solved for me.

“paths”: { “@angular/*“: [“../node_modules/@angular/*“] }

giorgiofellipe avatar Jun 12 '17 18:06 giorgiofellipe

Having the same problem the first time I make a ng serve, then I save a component and all is OK, ¿why?

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the functi
on or lambda with a reference to an exported function (position 109:9 in the original .ts file), resolving symbol AppModule in
 C:/Users/ivan/src/app/app.module.ts
webpack: Failed to compile.

And my app.module.ts pos 109 is: (backend: XHRBackend, defaultOptions: RequestOptions, router:Router) => { of the providers:

     {
      provide: Http,
      useFactory:
        (backend: XHRBackend, defaultOptions: RequestOptions, router:Router) => {
        return new AuthenticationBackendService(backend, defaultOptions, router);
      },
      deps: [XHRBackend, RequestOptions, Router]
    }

PriNcee11 avatar Jun 15 '17 14:06 PriNcee11

@PriNcee11 try to remove the arrow function with export function. Read the AOT guidelines in this article.

metodribic avatar Jun 16 '17 06:06 metodribic

still facing the same issue Error encountered resolving symbol values statically. Calling function 'getStates', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule

./router.ts
export function getStates(){
    let states = [];
    let loginState: Ng2StateDeclaration = {
        name: States.Login,
        url: '/login?redirectTo',
        component: LoginComponent,
        data: {
            title: "Login"
        }
    }
    states.push(loginState);
    return states;
}
import { getStates } from './router';

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent
  ],
  imports: [
    BrowserModule,
    UIRouterModule.forRoot({ states: getStates() , useHash: false })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

tejasrivastav avatar Jun 19 '17 12:06 tejasrivastav

I get this error when attempting to npm link to a local module control library

sgentile avatar Jun 21 '17 13:06 sgentile

I had this error (also disappearing after triggering recompile) with

// [...]
export const routes: any = [
   { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
   {
      [
         {
            path: 'dashboard',
            loadChildren: () => DashboardModule,
         },
// [...]

and was able to resolve it by changing it to

// [...]
export function getDashboardModule() { return DashboardModule };
export const routes: any = [
   { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
   {
      [
         {
            path: 'dashboard',
            loadChildren: getDashboardModule,
         },
// [...]

However this seems to be more of a workaround than a proper solution.

ScallyGames avatar Jun 26 '17 13:06 ScallyGames