Skip to content
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

DiscoveryService's getProviders and getControllers fail when metadata key is not applied at least once #12518

Closed
4 of 15 tasks
germangorodnev opened this issue Oct 6, 2023 · 1 comment · Fixed by #12519
Closed
4 of 15 tasks
Labels
needs triage This issue has not been looked into

Comments

@germangorodnev
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When using getProvider/getControllers with metadataKey parameter and there is no use of this metadata, i.e. decorator is not applied to any class, -- both methods fail due to wrappersByMetaKey being undefined.

Error:

TypeError: Cannot read properties of undefined (reading 'get')
    at DiscoverableMetaHostCollection.getProvidersByMetaKey (/home/projects/nestjs-typescript-starter-9qt4jp/node_modules/@nestjs/core/discovery/discoverable-meta-host-collection.js:46:34)
    at DiscoveryService.getProviders (/home/projects/nestjs-typescript-starter-9qt4jp/node_modules/@nestjs/core/discovery/discovery-service.js:42:98)
    at AppTestModule.onModuleInit (/home/projects/nestjs-typescript-starter-9qt4jp/dist/main.js:38:49)
    at callModuleInitHook (/home/projects/nestjs-typescript-starter-9qt4jp/node_modules/@nestjs/core/hooks/on-module-init.hook.js:51:35)
    at async NestApplication.callInitHook (/home/projects/nestjs-typescript-starter-9qt4jp/node_modules/@nestjs/core/nest-application-context.js:223:13)
    at async NestApplication.init (/home/projects/nestjs-typescript-starter-9qt4jp/node_modules/@nestjs/core/nest-application.js:100:9)
    at async bootstrap (/home/projects/nestjs-typescript-starter-9qt4jp/dist/main.js:55:5)

Not sure if this is intended, as they're supposed to behave like filters and could just return an empty array when there are no suitable providers/controllers.

Minimum reproduction code

https://stackblitz.com/edit/nestjs-discovery-service-issue?file=src%2Fmain.ts

Steps to reproduce

  1. npm i
  2. npm run start
  3. See error in the terminal

Then bring back @DiscoverDecorator on controller and provider - it will work.

Expected behavior

These methods could return [] instead.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.2.0+

Packages versions

Node.js version

18.18.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Let's track this here #12519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
2 participants