Angular 4 - Error detecting character values

One of my function modules has this content:

declare function require(name: string); @NgModule({ imports: [ // other modules here ChartModule.forRoot( require('highcharts'), require('highcharts/highcharts-more'), require('highcharts/modules/funnel'), require('highcharts/modules/heatmap') ) 

It works fine locally, but when I create it with the prod flag, it fails. The error I am getting is:

Error in error. Link to an unexported function (position 26:18 in the source .ts file), character resolution ....

A mistake in. /src/main.ts Module not found: Error: cannot resolve "./$$_gendir/app/app.module.ngfactory" to ...

Any idea on how to resolve this?

+5
source share
1 answer

I cannot tell you the exact string because you did not include the full @NgModule decorator. This error is usually found in the providers array if you have something like this:

 @NgModule({ // imports, exports and declarations providers: [{ provide: XSRFStrategy, useValue: new CookieXSRFStrategy('RESPONSE_TOKEN', 'RESPONSE_TOKEN') }] }) export class MyModule {} 

You cannot use AOT if you have a built-in function call. Instead, replace useValue with useFactory and the exported function (as indicated in the error message).

Here is the AOT-safe version of my first list:

 export function xsrfFactory() { return new CookieXSRFStrategy('XSRF-TOKEN', 'X-XSRF-TOKEN'); } @NgModule({ // imports, exports and declarations providers: [{ provide: XSRFStrategy, useFactory: xsrfFactory }] }) export class MyModule {} 
+1
source

Source: https://habr.com/ru/post/1266585/


All Articles