Skip to content

Calling function 'InjectionToken', function calls are not supported. #16762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fkolar opened this issue May 12, 2017 · 5 comments
Closed

Calling function 'InjectionToken', function calls are not supported. #16762

fkolar opened this issue May 12, 2017 · 5 comments

Comments

@fkolar
Copy link

fkolar commented May 12, 2017

I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
when I do ng build

I get:
Calling function 'InjectionToken', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol UserConfigToken in ....

I have created token and I am trying to use it as:

export const UserConfigToken = new InjectionToken<string>('User.Config');

export class CoreModule {
	 static forRoot(config: {[key: string]: any} = {}): ModuleWithProviders
    {
        return {
            ngModule: CoreModule,
            providers: [
                {provide: UserConfigToken, useValue: config},
}

Expected behavior

It will compile without these errors

I replaced OpaqueToken with InjectionToken and I think I am using it exactly the same one as in latest angular's 4.1.0 code e.g. when I look at
export const APP_BASE_HREF = new InjectionToken<string>('appBaseHref'); that I am using as well but I dont see any errors for this one.

I guess this usecase shoudl work...

What is the motivation / use case for changing the behavior?
OpaqueToken was deprecated

Please tell us about your environment:
I am running on latest Angular 4.1.0 as well as ng 1.0.3

Thanks for any input,

Frank

@fkolar
Copy link
Author

fkolar commented May 12, 2017

I tried to comment out all these usages and tested again and now I get more errors like:

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 /project/coreui/node_modules/@angular/core/core.d.ts, resolving symbol CoreModule in /project/coreui/src/lib/core/core.module.ts, resolving symbol CoreModule in /project/coreui/src/lib/core/core.module.ts

If I create ng new XXXX with the same angular version and use InjectionToken all works fine. It is just my existing project.

I will probably start removing libraries and dependencies to see if somethign is not related..

@fkolar
Copy link
Author

fkolar commented May 12, 2017

I found this issue on angular -cli angular/angular-cli#3854
whcih resolved my case.

adding path to my tsconfig

 "@angular/*": ["../node_modules/@angular/*"]

But stil not sure what is the real root case. It seems webpack is not able to find and map correct paths?

@fkolar fkolar closed this as completed May 12, 2017
@achieverprince
Copy link

@fkolar
Thanks for the solution, it worked for me too.

@allanjames
Copy link

Spent more time on this than I care to mention. fkolar saved me here as well. Many thanks

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants