angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.74k stars 11.98k forks source link

Error encountered resolving symbol values statically. #3843

Closed fkolar closed 7 years ago

fkolar commented 7 years ago

Please provide us with the following information:

ng --version angular-cli: 1.0.0-beta.24 node: 4.6.0 os: darwin x64 @angular/common: 2.4.1 @angular/compiler: 2.4.1 @angular/core: 2.4.1 @angular/forms: 2.4.1 @angular/http: 2.4.1 @angular/platform-browser: 2.4.1 @angular/platform-browser-dynamic: 2.4.1 @angular/router: 3.4.1 @angular/compiler-cli: 2.4.1

Today I have upgraded into the latest Angular -CLi from 22 build and I started to see this error.

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

my module looks like this:

@NgModule({
    declarations: [
        AppComponent ,
    ] ,
    imports: [
        MyCoreModule.forRoot({
            'restapi.context': '/assets/data/forms.json'
        }),
        AppRoutingModule ,
        PlaygroundModule
    ] ,
    providers: [ChoiceSourceRegistryService] ,
    entryComponents: [
        AppComponent ,

    ] ,
    bootstrap: [AppComponent]
})
export class AppModule
{

}

Any idea ? Why it started with buil #24. Is this related to the AOT?

hansl commented 7 years ago

Can you provide a project that reproduce this? We're missing a lot of information, but from what I can see your CoreModule is not declared properly.

fkolar commented 7 years ago

Hi Hans,

This project is not a public yet. Do you want me to copy the Core Module? It was all working fine with build 22.

Thanks, Frank

fkolar commented 7 years ago
export const UserConfig = new OpaqueToken('UserConfig');

/**
 * Core mode includes all shared logic accross whole application
 */
    // todo: for AOT use exported functions for factories insteads this inline ones.
@NgModule({
    imports: [
        BrowserModule , CommonModule , HttpModule ,
        TranslateModule.forRoot({
            provide: TranslateLoader ,
            useFactory: initTranslateLoader ,
            deps: [Http , Environment]
        })
    ] ,
    exports: [BrowserModule , CommonModule , HttpModule , TranslateModule , LocalizedImageDirective] ,
    declarations: [LocalizedImageDirective , NotFoundComponent ] ,
    bootstrap: []

})
export class MyCoreModule
{

    static forRoot (config: {[key: string]: any} = {}): ModuleWithProviders
    {
        // when empty we asume we are in Test. Application should always have some basic initialization
        if (Object.keys(config).length === 0) {
            config[AppConfig.InTest] = true;
        }

        return {
            ngModule: MyCoreModule ,
            providers: [

                {provide: UserConfig , useValue: config} ,
                {provide: AppConfig , useFactory: makeConfig , deps: [UserConfig , Injector]} ,
                {provide: DefaultRequestOptions , useClass: DefaultRequestOptions , deps: [AppConfig]} ,

                {provide: RequestOptions , useClass: DefaultRequestOptions , deps: [AppConfig]} ,

                {
                    provide: Http , useFactory: makeHttp ,
                    deps: [XHRBackend , DefaultRequestOptions , ErrorNotifierService , AppConfig]
                } ,
                {provide: RoutingService , useClass: RoutingService , deps: [Router]} ,

                EntityResource ,
                ErrorNotifierService ,
                Environment ,

                {
                    'provide': APP_INITIALIZER ,
                    'useFactory': initI18nSupport ,
                    'deps': [AppConfig] ,
                    'multi': true ,
                }
            ]
        };
    }

}

export function initI18nSupport (appConfig: AppConfig): Function
{
    return () => appConfig.initializeI18n();
}

export function initTranslateLoader (http: Http , env: Environment)
{
    return new DefaultTranslateLoader(http , env , '/assets/i18n' , '.json');
}
hansl commented 7 years ago

Okay, could you try to change your tsconfig.json file to add "files": ["main"], then from the command line, run node_modules/.bin/ngc -p src/tsconfig.json? See if that shows an error (it should). Please paste the result if it does.

fkolar commented 7 years ago

this is my tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
  "files": ["main"]
}
fkolar commented 7 years ago

When I run it the result is:

Type NgbHighlight in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/highlight.d.ts is part of the declarations of 2 modules: NgbTypeaheadModule in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.d.ts and NeptunComponentsModule in /Neptun/aw7/AngularMetaUI/src/app/shared/components/neptun.component.module.ts! Please consider moving NgbHighlight in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/highlight.d.ts to a higher module that imports NgbTypeaheadModule in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.d.ts and NeptunComponentsModule in /Neptun/aw7/AngularMetaUI/src/app/shared/components/neptun.component.module.ts. You can also create a new NgModule that exports and includes NgbHighlight in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/highlight.d.ts then import that NgModule in NgbTypeaheadModule in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.d.ts and NeptunComponentsModule in /Neptun/aw7/AngularMetaUI/src/app/shared/components/neptun.component.module.ts.
hansl commented 7 years ago

You should try to do what it says :)

Here it is pasted without the formatting:

Type NgbHighlight in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/highlight.d.ts is part of the declarations of 2 modules: NgbTypeaheadModule in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.d.ts and NeptunComponentsModule in /Neptun/aw7/AngularMetaUI/src/app/shared/components/neptun.component.module.ts! Please consider moving NgbHighlight in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/highlight.d.ts to a higher module that imports NgbTypeaheadModule in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.d.ts and NeptunComponentsModule in /Neptun/aw7/AngularMetaUI/src/app/shared/components/neptun.component.module.ts. You can also create a new NgModule that exports and includes NgbHighlight in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/highlight.d.ts then import that NgModule in NgbTypeaheadModule in /Neptun/aw7/AngularMetaUI/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.d.ts and NeptunComponentsModule in /Neptun/aw7/AngularMetaUI/src/app/shared/components/neptun.component.module.ts.

fkolar commented 7 years ago

Changed and now it actually throws my original error

Error: Error encountered resolving symbol values statically. Calling function 'MyCoreModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /Neptun/aw7/AngularMetaUI/src/app/app.module.ts, resolving symbol AppModule in /Neptun/aw7/AngularMetaUI/src/app/app.module.ts at simplifyInContext (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:25713:25) at StaticReflector.simplify (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:25725:15) at StaticReflector.annotations (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:25223:62) at NgModuleResolver.resolve (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:17583:84) at CompileMetadataResolver.getNgModuleMetadata (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:18091:62) at addNgModule (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:24985:60) at /Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:24996:16 at Array.forEach (native) at _createNgModules (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:24995:28) at analyzeNgModules (/Neptun/aw7/AngularMetaUI/node_modules/@angular/compiler/bundles/compiler.umd.js:24870:16) Compilation failed

fkolar commented 7 years ago

Or maybe the forRoot is too complex to be resolved by this StaticReflector.simplify ?

hansl commented 7 years ago

Sorry. I missed the if() statement the first time around. forRoot() macro functions can only be a single return statement and does not contain any branching or complex logic.

fkolar commented 7 years ago

Is this something new when build 22 did not catch this?

hansl commented 7 years ago

This should have not been working with beta 22 either. We enabled more features in beta 22 and this was one of the thing (lazy route splitting).

fkolar commented 7 years ago

Excellent the if thingy is gone and the error is gone. Thanks for the quick response.

now I just need to resolved other ones as well, but probably will create new issue as this does not relates anymore to this context

ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve 'app.component.html'

btw. I just double checked and I had version 21.

{
  "project": {
    "version": "1.0.0-beta.21",
    "name": "angular-meta-ui"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets"
fkolar commented 7 years ago

so my second errors does not seems to be problem anymore as my @component properties were before declared as:

 templateUrl: 'app.component.html' ,
    styleUrls: ['app.component.scss']

when I changed this to :

 templateUrl: './app.component.html' ,
styleUrls: ['./app.component.scss']

it works

angular-automatic-lock-bot[bot] commented 5 years ago

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.