You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### Investigating the "Cannot resolve dependency" error
64
+
65
+
> info **Note** This feature is supported for `@nestjs/core` >= `v9.3.10`.
66
+
67
+
Probably the most common error message you might have seen is about Nest not being able to resolve dependencies of a provider. Using Nest Devtools, you can effortlessly identify the issue and learn how to resolve it.
68
+
69
+
First, open up the `main.ts` file and update the `bootstrap()` call, as follows:
Also, make sure to set the `abortOnError` to `false`:
79
+
80
+
```typescript
81
+
const app =awaitNestFactory.create(AppModule, {
82
+
snapshot: true,
83
+
abortOnError: false, // <--- THIS
84
+
});
85
+
```
86
+
87
+
Now every time your application fails to bootstrap due to the **"Cannot resolve dependency"** error, you'll find the `graph.json` (that represents a partial graph) file in the root directory. You can then drag & drop this file into Devtools (make sure to switch the current mode from "Interactive" to "Preview"):
As you can see, the highlighted `TasksModule` is the one we should look into. Also, in the dialog window you can already see some instructions on how to use fix this issue.
96
+
97
+
If we switch to the "Classes" view instead, that's what we'll see:
This graph illustrates that the `DiagnosticsService` which we want to inject into the `TasksService` was not found in the context of the `TasksModule` module, and we should likely just import the `DiagnosticsModule` into the `TasksModule` module to fix this up!
102
+
63
103
#### Routes explorer
64
104
65
105
When you navigate to the **Routes explorer** page, you should see all of the registered entrypoints:
Copy file name to clipboardExpand all lines: content/faq/errors.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,8 @@ Potential solutions:
20
20
21
21
The most common culprit of the error, is not having the `<provider>` in the module's `providers` array. Please make sure that the provider is indeed in the `providers` array and following [standard NestJS provider practices](/fundamentals/custom-providers#di-fundamentals).
22
22
23
+
<app-banner-devtools></app-banner-devtools>
24
+
23
25
There are a few gotchas, that are common. One is putting a provider in an `imports` array. If this is the case, the error will have the provider's name where `<module>` should be.
24
26
25
27
If you run across this error while developing, take a look at the module mentioned in the error message and look at its `providers`. For each provider in the `providers` array, make sure the module has access to all of the dependencies. Often times, `providers` are duplicated in a "Feature Module" and a "Root Module" which means Nest will try to instantiate the provider twice. More than likely, the module containing the `<provider>` being duplicated should be added in the "Root Module"'s `imports` array instead.
0 commit comments