-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Missing @Injectable()
or @Inject()
decorators silently injects undefined
#13899
Comments
this is expected due to TypeScript introspection limitations. I believe that you can use ESLint with plugins like https://github.com/darraghoriordan/eslint-plugin-nestjs-typed/ to detect such cases. Neither |
But this lint plugin is not mentioned in the docs and does not come with default Nest.js installation. @micalevisk I don't think it's very user friendly to not document known issues and just give link once to some third party solution in case someone stumbles upon this problem. |
Got you. Few free to open a PR on the docs github repo to document that. There is a PR open already that covers such topic but maybe having a 'known limitations' page would be better |
Linking this one because this issue happened before: #13059. I might find some time to submit docs PR later. |
Is there an existing issue for this?
Current behavior
Missing
@Injectable()
or@Inject()
decorators silently injectsundefined
.This is a major issue as it does not prevent Nest.js application from starting and it's very easy to miss this in tests when mocking methods that use these broken injectables.
Notice the log output in the following repro:
Case 1
Case 2
Case 3
Case 1
is unexpected and should not happen / everyone needs to be aware of this problem.Minimum reproduction code
https://github.com/glebbash/nest-injectable-repro
Steps to reproduce
npm ci
npm start
Expected behavior
There should be an error thrown, stopping the application from initializing or this issue must be documented.
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 package
No response
NestJS version
^10.3.1
Packages versions
Node.js version
20
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: