Skip to content

Commit 00d5263

Browse files
committed
fix(core): fix unknown dependencies exception
1 parent 3365ecc commit 00d5263

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

packages/core/errors/messages.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Module } from '../injector/module';
1010
* Returns the name of an instance
1111
* @param instance The instance which should get the name from
1212
*/
13-
const getInstanceName = (instance: unknown) =>
13+
const getInstanceName = (instance: unknown): string =>
1414
instance && (instance as Type<any>).name;
1515

1616
/**
@@ -19,13 +19,13 @@ const getInstanceName = (instance: unknown) =>
1919
* (= injection token). As fallback it returns '+'
2020
* @param dependency The dependency whichs name should get displayed
2121
*/
22-
const getDependencyName = (dependency: InjectorDependency) =>
22+
const getDependencyName = (dependency: InjectorDependency): string =>
2323
// use class name
2424
getInstanceName(dependency) ||
2525
// use injection token (symbol)
2626
(isSymbol(dependency) && dependency.toString()) ||
2727
// use string directly
28-
dependency ||
28+
(dependency as string) ||
2929
// otherwise
3030
'+';
3131

@@ -49,15 +49,16 @@ export const UNKNOWN_DEPENDENCIES_MESSAGE = (
4949
key,
5050
} = unknownDependencyContext;
5151
const moduleName = getModuleName(module) || 'Module';
52+
const dependencyName = getDependencyName(name);
5253

5354
let message = `Nest can't resolve dependencies of the ${type.toString()}`;
5455

5556
const potentialSolutions = `\n
5657
Potential solutions:
57-
- If ${name} is a provider, is it part of the current ${moduleName}?
58-
- If ${name} is exported from a separate @Module, is that module imported within ${moduleName}?
58+
- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
59+
- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
5960
@Module({
60-
imports: [ /* the Module containing ${name} */ ]
61+
imports: [ /* the Module containing ${dependencyName} */ ]
6162
})
6263
`;
6364

@@ -70,7 +71,7 @@ Potential solutions:
7071

7172
message += ` (`;
7273
message += dependenciesName.join(', ');
73-
message += `). Please make sure that the argument ${name} at index [${index}] is available in the ${getModuleName(
74+
message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${getModuleName(
7475
module,
7576
)} context.`;
7677
message += potentialSolutions;

packages/core/injector/injector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface InjectorDependencyContext {
5555
/**
5656
* The name of the function or injection token
5757
*/
58-
name?: string;
58+
name?: string | symbol;
5959
/**
6060
* The index of the dependency which gets injected
6161
* from the dependencies array
@@ -411,7 +411,7 @@ export class Injector {
411411
}
412412

413413
public async lookupComponent<T = any>(
414-
providers: Map<string, InstanceWrapper>,
414+
providers: Map<string | symbol, InstanceWrapper>,
415415
module: Module,
416416
dependencyContext: InjectorDependencyContext,
417417
wrapper: InstanceWrapper<T>,

0 commit comments

Comments
 (0)