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
- The dependency at index [${index}] appears to be undefined at runtime
86
+
- This commonly occurs when using 'import type' instead of 'import' for injectable classes
87
+
- Check your imports and change:
88
+
❌ import type { SomeService } from './some.service';
89
+
✅ import { SomeService } from './some.service';
90
+
- Ensure the imported class is decorated with @Injectable() or is a valid provider
91
+
- If using dynamic imports, ensure the class is available at runtime, not just for type checking
92
+
93
+
For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors`;
94
+
}else{
95
+
potentialSolutions=
96
+
// If module's name is well defined
97
+
moduleName!=='current'
98
+
? `\n
76
99
Potential solutions:
77
100
- Is ${moduleName} a valid NestJS module?
78
101
- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
79
102
- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
80
103
@Module({
81
104
imports: [ /* the Module containing ${dependencyName} */ ]
82
105
})
83
-
`
84
-
: `\n
106
+
107
+
For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors`
108
+
: `\n
85
109
Potential solutions:
86
110
- If ${dependencyName} is a provider, is it part of the current Module?
87
111
- If ${dependencyName} is exported from a separate @Module, is that module imported within Module?
88
112
@Module({
89
113
imports: [ /* the Module containing ${dependencyName} */ ]
90
114
})
91
-
`;
115
+
116
+
For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors`;
117
+
}
92
118
93
119
letmessage=`Nest can't resolve dependencies of the ${type.toString()}`;
94
120
@@ -103,7 +129,7 @@ Potential solutions:
103
129
104
130
message+=` (`;
105
131
message+=dependenciesName.join(', ');
106
-
message+=`). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${moduleName} context.`;
132
+
message+=`). Please make sure that the argument ${isImportTypeIssue ? 'dependency' : dependencyName} at index [${index}] is available in the ${isImportTypeIssue ? 'current' : moduleName} context.`;
it('should detect likely import type issue and provide specific guidance',()=>{
218
+
constexpectedResult=
219
+
stringCleaner(`Nest can't resolve dependencies of the ResourceController (ResourceService, ?). Please make sure that the argument dependency at index [1] is available in the current context.
220
+
221
+
Potential solutions:
222
+
- The dependency at index [1] appears to be undefined at runtime
223
+
- This commonly occurs when using 'import type' instead of 'import' for injectable classes
224
+
- Check your imports and change:
225
+
❌ import type { SomeService } from './some.service';
226
+
✅ import { SomeService } from './some.service';
227
+
- Ensure the imported class is decorated with @Injectable() or is a valid provider
228
+
- If using dynamic imports, ensure the class is available at runtime, not just for type checking
229
+
230
+
For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors
dependencies: ['ResourceService',Object],// Object simulates import type issue
237
+
name: 'SomeService',
238
+
}).message,
239
+
);
240
+
241
+
expect(actualMessage).to.equal(expectedResult);
242
+
});
243
+
it('should detect import type issue with mixed dependencies',()=>{
244
+
constexpectedResult=
245
+
stringCleaner(`Nest can't resolve dependencies of the ResourceController (ValidService, ?, AnotherService). Please make sure that the argument dependency at index [1] is available in the current context.
246
+
247
+
Potential solutions:
248
+
- The dependency at index [1] appears to be undefined at runtime
249
+
- This commonly occurs when using 'import type' instead of 'import' for injectable classes
250
+
- Check your imports and change:
251
+
❌ import type { SomeService } from './some.service';
252
+
✅ import { SomeService } from './some.service';
253
+
- Ensure the imported class is decorated with @Injectable() or is a valid provider
254
+
- If using dynamic imports, ensure the class is available at runtime, not just for type checking
255
+
256
+
For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors
it('should add documentation links to export errors',()=>{
273
+
constexpectedResult=
274
+
stringCleaner(`Nest cannot export a provider/module that is not a part of the currently processed module (TestModule). Please verify whether the exported TestService is available in this particular context.
275
+
276
+
Possible Solutions:
277
+
- Is TestService part of the relevant providers/imports within TestModule?
278
+
279
+
For more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors
0 commit comments