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.

TypeError: Cannot read property 'get' of undefined

See original GitHub issue

When inject a service in controller using the decorator

How to reproduce:

import { Controller, GET, Inject } from "fastify-decorators";
import { AnyService } from "../services";

@Controller("/status")
export default class HelloController {
  @Inject(AnyService)
  private anyService: AnyService;

  @GET()
  async handler(): Promise<{ hello: string }> {
    try {
      console.log(this.anyService);
    } catch (e) {
      console.log(e);
    }
    return { hello:  "world" };
  }
}

TypeError: Cannot read property 'get' of undefined
    at StatusController.get [as cache] (/home/ferco/workspace/http-service-template/lib/decorators/inject.ts:26:42)
    at StatusController.<anonymous> (/home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:35:24)
    at Generator.next (<anonymous>)
    at /home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:17:71
    at new Promise (<anonymous>)
    at __awaiter (/home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:13:12)
    at StatusController.handler (/home/ferco/workspace/http-service-template/src/controllers/status.controller.ts:41:16)
    at Object.<anonymous> (/home/ferco/workspace/http-service-template/lib/decorators/strategies/controller-type.ts:52:61)
    at preHandlerCallback (/home/ferco/workspace/http-service-template/node_modules/fastify/lib/handleRequest.js:120:28)
    at preValidationCallback (/home/ferco/workspace/http-service-template/node_modules/fastify/lib/handleRequest.js:103:5)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
L2jLigacommented, Jul 31, 2020

Released as v3.1.1

1reaction
L2jLigacommented, Jul 31, 2020

Thanks for clarification! I will take a look what I can do on it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined. Undefined means that a variable has been declared but has not been assigned a value....
Read more >
TypeError: Cannot read property 'get' of undefined on AngularJS
You are getting this error because $http is undefined in your factory. You can fix it by passing it to the factory like...
Read more >
Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
TypeError: Cannot read property 'get' of undefined at Object ...
I can't provide a link to a playground as this issue seems to be tied to the structure of the repository and dependencies....
Read more >
TypeError: Cannot read property 'get' of undefined - Code Help
Code : let prefix = client.guildSettings.get(message.guild.id,"prefix") Error : TypeError: Cannot read property 'get' of undefined Can ...
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