question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong error about non exported function for decorators

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
DzmitryShylovichcommented, Mar 19, 2017

The problem here is that Logger is an object. You can’t use arbitrary objects as provider tokens. Use:

  1. string
  2. InjectionToken
  3. class/abstract class

and it will work

0reactions
angular-automatic-lock-bot[bot]commented, Jun 14, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

References to a non-exported class are not supported in ...
The error is exporting. so guys use export keyword in front of class Message . hope this will remove your error during prod...
Read more >
Builtin "export" decorator/function - #6 by smontanaro - Ideas
Here's the barebones export_example module. I'm sure the export decorator doesn't adhere to recommended practice and doesn't trap any user mistakes, but itΒ ......
Read more >
AOT metadata errors - Angular
Angular generates a class factory in a separate module and that factory can only access exported functions. To correct this error, export the...
Read more >
Understanding JavaScript decorators - LogRocket Blog
Learn about JavaScript's function decorators and class decorators as well as how you can create clean and reusable decorators.
Read more >
TorchScript β€” PyTorch 1.13 documentation
This class errors if not all nodes have been fused in inference, ... This decorator indicates to the compiler that a function or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found