<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/i-found-and-fixed-a-bug-in-the-nestjs-core--ukmki3qjk" -->

---
title: I found and fixed a bug in the NestJS core! | daily.dev
description: A developer discovered a bug in NestJS's DI container where registering the same provider token via both `forRoot()` (global scope) and `forFeature()` (feature...
canonical: https://daily.dev/posts/i-found-and-fixed-a-bug-in-the-nestjs-core--ukmki3qjk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: I found and fixed a bug in the NestJS core! | daily.dev
og:description: A developer discovered a bug in NestJS's DI container where registering the same provider token via both `forRoot()` (global scope) and `forFeature()` (feature...
og:url: https://daily.dev/posts/i-found-and-fixed-a-bug-in-the-nestjs-core--ukmki3qjk
og:image: https://api.daily.dev/og/posts/UkMKi3qjK.png
og:image:alt: I found and fixed a bug in the NestJS core!
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# I found and fixed a bug in the NestJS core!

**[Vilancer](https://daily.dev/sources/vilancer)** · [@malekelkssas](https://daily.dev/malekelkssas) · 1 min read · 0 upvotes · 0 comments

## Summary

A developer discovered a bug in NestJS's DI container where registering the same provider token via both `forRoot()` (global scope) and `forFeature()` (feature module scope) caused the controller and service within the same feature module to receive two different instances instead of one shared instance. After cloning the NestJS repo and tracing the issue with AI tooling, the root cause was identified as a flaw in how the DI container resolves scoped providers registered at multiple levels. The fix was submitted and accepted as a PR to the NestJS core repository.

## Content

While digging into NestJS's dynamic modules, I registered the same provider token with both `forRoot()` (global scope) and `forFeature()` (inside a feature module).

Expected: one shared instance of that provider.

Actual: the controller and the service in the same feature module resolved two different instances of the "same" token (not what I expected).

I cloned the NestJS repo and used some AI tools to help trace it down to how the DI container resolves scoped providers when a token is registered at both levels (turned out to be a genuine bug in the resolution logic, not a misunderstanding on my end).

Ended up being my first accepted contribution to NestJS 🎉

🔗 Issue: [https://github.com/nestjs/nest/issues/17136](https://github.com/nestjs/nest/issues/17136)

🔗 PR: [https://github.com/nestjs/nest/pull/17141](https://github.com/nestjs/nest/pull/17141)

## Similar posts on daily.dev

- [NestJS Dependency Injection: Source Code, Type Erasure Hacks, and Building Your Own IoC Container from Scratch](https://daily.dev/posts/nestjs-dependency-injection-source-code-type-erasure-hacks-and-building-your-own-ioc-container-fr-74fnlhzd6) · Medium · 0 upvotes · 0 comments
- [How Domain Boundary Violations Slowly Destroy Your Codebase](https://daily.dev/posts/how-domain-boundary-violations-slowly-destroy-your-codebase-enay5y3sz) · Towards Dev · 15 upvotes · 0 comments
- [Frontend Dependency Injection: From Context API to Composition Root](https://daily.dev/posts/frontend-dependency-injection-from-context-api-to-composition-root-pfhfninwc) · ITNEXT · 17 upvotes · 3 comments
- [Angular Dependency Injection Is a Tree Search, Not Magic](https://daily.dev/posts/angular-dependency-injection-is-a-tree-search-not-magic-om4axsm1e) · Medium · 3 upvotes · 0 comments

---

Tags: [#open-source](https://daily.dev/tags/open-source), [#typescript](https://daily.dev/tags/typescript), [#dependency-injection](https://daily.dev/tags/dependency-injection), [#nestjs](https://daily.dev/tags/nestjs)

[View this post on daily.dev](https://daily.dev/posts/i-found-and-fixed-a-bug-in-the-nestjs-core--ukmki3qjk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/i-found-and-fixed-a-bug-in-the-nestjs-core--ukmki3qjk","headline":"I found and fixed a bug in the NestJS core!","text":"A developer discovered a bug in NestJS's DI container where registering the same provider token via both `forRoot()` (global scope) and `forFeature()` (feature module scope) caused the controller and service within the same feature module to receive two different instances instead of one shared instance. After cloning the NestJS repo and tracing the issue with AI tooling, the root cause was identified as a flaw in how the DI container resolves scoped providers registered at multiple levels. The fix was submitted and accepted as a PR to the NestJS core repository.","url":"https://daily.dev/posts/i-found-and-fixed-a-bug-in-the-nestjs-core--ukmki3qjk","datePublished":"2026-07-10T13:46:16.369Z","dateModified":"2026-07-10T23:34:31.683Z","author":{"@type":"Person","name":"malek elkssas","url":"https://daily.dev/malekelkssas","image":"https://lh3.googleusercontent.com/a/ACg8ocKx0ybioVAY712uZwxeGuRHysZlBel_k8N0rmokAJzgmax1tA=s96-c","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":110}},"image":"https://media.daily.dev/image/upload/s--Wz5Aj0Pm--/f_auto/v1783691177/posts/UkMKi3qjK?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/vilancer","name":"Vilancer"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Vilancer","item":"https://daily.dev/squads/vilancer"},{"@type":"ListItem","position":3,"name":"I found and fixed a bug in the NestJS core!"}]}
```

