Wrong error about non exported function for decorators
See original GitHub issueIβm researching a lot but all I found is βdo this and it will workβ but it does not. Also the error message can not be correct and it is working when I save the file again.
Iβm submitting a β¦ (check one with βxβ)
[x] bug report
[ ] feature request
[ ] support request
Current behavior
When I start ng serve
and everything is compiled already I get the following error:
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 (position 17:12 in the original .ts file), resolving symbol TranslateLogHandler in /home/iras/work/angular2-cli-t
est/node_modules/angular2-translator/src/TranslateService.ts, resolving symbol TranslateLogHandler in /home/iras/work/angular2-cli-test/node_modules/angular2-translator/index.d.ts, resolving symbol AppModule in /home/iras/work/angular2-cli-test/src/app/app.module.ts, resolving symbol AppModul
e in /home/iras/work/angular2-cli-test/src/app/app.module.ts
Yes, of course you will write use an exported function - please have a look in Minimal reproduction of the problem with instructions.
When I save/touch the file (update mtime from file) while ng-serve is running. It gets recompiled without error: webpack: Compiled successfully.
.
Expected behavior It should always work not just sometimes.
Minimal reproduction of the problem with instructions
Create a new project ng new justAnotherBug
. And a file src/app/Logger.ts
with the following content:
export const Logger = {
debug: () => {},
error: (message) => console && console.error && console.error(message),
info: () => {},
}
Write this in your app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { Logger } from './Logger';
export function getLogger() {
return {
debug: () => {},
error: (message) => console && console.error && console.error(message),
info: (message) => console && console.log && console.log(message),
};
};
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [
{ provide: Logger, useFactory: getLogger, deps: [] }
],
bootstrap: [AppComponent]
})
export class AppModule { }
Finally run ng serve
. When it works: restart ng serve
without modifying the file again (first time it will work usually).
What is the motivation / use case for changing the behavior? The use case is to overwrite the Logger for this application (the Logger could be from any third party module).
Please tell us about your environment:
$ uname -sr
Linux 4.9.13-1-MANJARO
$ npm --version
4.4.1
$ node --version
v7.7.2
node: 7.7.2
$ npm list |egrep '(\@angular|typescript)'
βββ¬ @angular/cli@1.0.0-rc.2
β βββ¬ @angular/tsc-wrapped@0.5.2
β βββ typescript@2.1.6
βββ @angular/common@2.4.10
βββ @angular/compiler@2.4.10
βββ¬ @angular/compiler-cli@2.4.10
βββ @angular/core@2.4.10
βββ @angular/forms@2.4.10
βββ @angular/http@2.4.10
βββ @angular/platform-browser@2.4.10
βββ @angular/platform-browser-dynamic@2.4.10
βββ @angular/router@3.4.10
βββ typescript@2.0.10
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (4 by maintainers)
The problem here is that
Logger
is an object. You canβt use arbitrary objects as provider tokens. Use:InjectionToken
and it will work
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.