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

Error in module.ngFactory. Calling function 'document', function calls are not supported

Open zzx88991 opened this issue 9 years ago • 3 comments

OS?

windows 10

Versions.

@angular/cli: 1.0.0-beta.31 node: 7.1.0 os: win32 x64 @angular/common: 2.4.7 @angular/compiler: 2.4.7 @angular/compiler-cli: 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/platform-server: 2.4.7 @angular/router: 3.0.0 @angular/upgrade: 2.4.7 @ngtools/webpack: 1.2.9

Repro steps.

Webpack aot plugin was used to compile the angular app. The intention of this part code is to retrieve server-side state stored in a hidden element by using document.querySelector

In module.ts,

import { StoreModule } from '@ngrx/store';
import { getRehydratedState } from './rehydratedState';
@NgModule({
    imports:[
        StoreModule.provideStore(reducer, getRehydratedState('RehydratedState') )
    ]
})

in rehydratedState.ts

export function getRehydratedState(selector: string): string {
    return document.querySelector(selector).textContent;
}

The log given by the failure.

Error encountered resolving symbol values statically. Calling function 'document', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol getRehydratedState...

Mention any other details that might be useful.

Seems like angular static analyzer doesn't like document

zzx88991 avatar Feb 27 '17 18:02 zzx88991

you can't have function calls in your decorators. Decorators need to be static.

deebloo avatar Feb 27 '17 18:02 deebloo

What @deebloo said. The Angular annotations are supposed to be fully static.

hansl avatar Feb 27 '17 18:02 hansl

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.