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

@ngtools/webpack - Error encountered resolving symbol values statically

Open ajantsch opened this issue 9 years ago • 77 comments

Versions.

Repro steps.

Not really repro steps, but the not-changed webpack config used to work with [email protected] and @ngtools/[email protected], since upgrading I get the error described below and I have no idea what to do about it.

The log given by the failure.

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AnimationDriver in /Users/ajantsch/Dropbox/Projects/22_9Cookies/transmission-web-client/webkick/node_modules/@angular/platform-browser/src/dom/animation_driver.d.ts, resolving symbol BrowserTestingModule in /Users/ajantsch/Dropbox/Projects/22_9Cookies/transmission-web-client/webkick/node_modules/@angular/platform-browser/testing/browser.d.ts, resolving symbol BrowserTestingModule in /Users/ajantsch/Dropbox/Projects/22_9Cookies/transmission-web-client/webkick/node_modules/@angular/platform-browser/testing/browser.d.ts

ERROR in ./src/bootstrap.ts
Module not found: Error: Can't resolve './../$$_gendir/src/app/main.module.ngfactory' in '/Users/ajantsch/Dropbox/Projects/22_9Cookies/transmission-web-client/webkick/src'
 @ ./src/bootstrap.ts 3:0-83

ERROR in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
Module not found: Error: Can't resolve '/Users/ajantsch/Dropbox/Projects/22_9Cookies/transmission-web-client/webkick/$$_gendir' in '/Users/ajantsch/Dropbox/Projects/22_9Cookies/transmission-web-client/webkick/node_modules/@angular/core/src/linker'
 @ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js 69:15-36 85:15-102
 @ ./~/@angular/core/src/linker.js
 @ ./~/@angular/core/src/core.js
 @ ./~/@angular/core/index.js
 @ ./src/bootstrap.ts

ajantsch avatar Dec 21 '16 10:12 ajantsch

Same problem. So?

Serginho avatar Feb 07 '17 12:02 Serginho

This issue looks to be a duplicate of https://github.com/angular/angular-cli/issues/3707

christianacca avatar Feb 07 '17 13:02 christianacca

I'm getting a similar error: ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '[...]/src' @ ./src/main.ts 4:0-74 @ multi ./src/main.ts

tschaka1904 avatar Feb 10 '17 17:02 tschaka1904

I get the same error:

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '...' @ ./src/main.ts 4:0-74 @ multi ./src/main.ts

Indreed avatar Feb 13 '17 10:02 Indreed

Please, someone help us.

gbedell avatar Feb 13 '17 21:02 gbedell

As many, I was exposed after an ugrade to the message

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function,.....

My cause was in the reducers, who worked perfectly with 2.3 The solution was to replace export const myReducer: ActionReducer<string> = function(state: string = "pipo", action: Action){ by export function myReducer(state: string = "pipo", action: Action){ I hope it help getting from the hole I was stuck in for quite a few hours... Alex

alexmasselot avatar Feb 14 '17 07:02 alexmasselot

Testing it out a bit with ng2-toastr with

@angular/cli: 1.0.0-beta.31
node: 7.5.0
os: darwin x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.31
@angular/compiler-cli: 2.4.7

And consider following import provided in app.module.ts for all examples below:

import { ToastModule, ToastOptions } from 'ng2-toastr/ng2-toastr';

The following does not work (resulting in the error further down):

Case 1

export const globalToastOptions: ToastOptions = new ToastOptions({
  animate: 'flyRight',
  positionClass: 'toast-bottom-right'
});

@NgModule({
  imports: [
    ToastModule.forRoot(globalToastOptions)
  ],
  ...
})

Case 2

export function globalToastOptions() {
  return new ToastOptions({
    animate: 'flyRight',
    positionClass: 'toast-bottom-right'
  });
}

@NgModule({
  imports: [
    ToastModule.forRoot(globalToastOptions())
  ],
  ...
})

Case 3

@NgModule({
  imports: [
    ToastModule.forRoot(new ToastOptions({
      animate: 'flyRight',
      positionClass: 'toast-bottom-right'
    }))
  ],
  ...
})

Error

ng build output:

ERROR in Error encountered resolving symbol values statically. Calling function 'ToastOptions', function calls are not supported. Consider replacing the function or lambda
 with a reference to an exported function, resolving symbol globalToastOptions in /WebApp/src/app/app.module.ts, resolving symbol AppModule in /WebApp/src/app/app
.module.ts, resolving symbol AppModule in /WebApp/src/app/app.module.ts, resolving symbol AppModule in /WebApp/src/app/app.module.ts

However, the following does work:

Case 4

@NgModule({
  imports: [
    ToastModule.forRoot()
  ],
  ...
})

Case 5

@NgModule({
  imports: [
    ToastModule.forRoot({
      animate: 'flyRight',
      positionClass: 'toast-bottom-right'
    })
  ],
  ...
})

In my case this solves the issue for ng2-toastr, but I still have problems with angular2-highcharts and a suggested workaround doesn't quite cut it for my implementation.

It would be nice if someone on the angular team could dive into what's causing this. At least use a warning instead of error.

marioleed avatar Feb 15 '17 10:02 marioleed

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /Users/Test-PRJ/PRJ/AJ/Projects/Test/Test-Source/src/app/app.module.ts, resolving symbol AppModule in /Users/Test-PRJ/PRJ/AJ/Projects/Test/Test-Source/src/app/app.module.ts

Stuck with this issue, Now i cant run the project as well as build

Pinank avatar Feb 16 '17 15:02 Pinank

WARNING in ./~/@angular/router/src/router_module.js 303:51-71 "export 'LOCATION_INITIALIZED' was not found in '@angular/common' webpack: Compiled with warnings.

bodyazinchenko avatar Feb 21 '17 12:02 bodyazinchenko

We were able to solve our ./../$$_gendir/src/app/main.module.ngfactory by ensuring we removed all modules/files that weren't being used.

angular.cli 1.0.0-beta33 and angular 2.4.1

mkonecny avatar Feb 21 '17 21:02 mkonecny

I had this error when in appModule was

{ path: "work", loadChildren: "/modules/social/work/WorkModule#WorkModule" }

Slashmsu avatar Feb 21 '17 21:02 Slashmsu

I have this issue

xe4me avatar Feb 22 '17 05:02 xe4me

@deot can reply, your full tsconfig.json file. I tried to add your lines but nothing change.

Gonic0 avatar Feb 22 '17 15:02 Gonic0

See next. I found a solution for me.

I hope this helps.

Gonic0 avatar Feb 23 '17 12:02 Gonic0

This is preventing production deploys, isn't it?

avatsaev avatar Feb 27 '17 21:02 avatsaev

Please make sure you delete your project dependencies of the old angular-cli in your package.json using:

npm uninstall --save angular-cli

An issue was having the same error as stated above and I found this to be the solution, might be helpful for someone else.

RicardoVaranda avatar Mar 01 '17 14:03 RicardoVaranda

I fixed this issue by removing all function calls from my static forRoot() functions. I replaced those functions with factory functions declared/referenced by the provider instead.

So in @marioleed's cases that didn't work (1-3) you can see that functions were called during configuration, whereas on the others they are objects using the Typescript Class as an Interface.

There's probably a good reason for not allowing arbitrary functions to be called at the configuration stage, but I'm too new to Angular to comment on exactly why.

dereekb avatar Mar 05 '17 02:03 dereekb

Any solution ?

miton18 avatar Mar 15 '17 07:03 miton18

Keep getting this error with ng serve:

ERROR in this.symbolResolver.getSymbolByModule is not a function

with angular and angular/cli latest version. Since my project relies on primeng ultima template, I'm Trying to keep my project as close as possible to ultima demo project, which compiles correctly whereas mine doesn't.

pierfreeman avatar Mar 15 '17 15:03 pierfreeman

Ant solution for this. Im facing this issue.

knvpk avatar Mar 28 '17 05:03 knvpk