Skip to content

Commit

Permalink
feat(core): add hint to unknown dependency error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Nov 12, 2022
1 parent 8e3af06 commit 96e4e8d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/core/errors/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,30 @@ export const UNKNOWN_DEPENDENCIES_MESSAGE = (
dependencies,
key,
} = unknownDependencyContext;
const moduleName = getModuleName(module) || 'Module';
const moduleName = getModuleName(module) || undefined;
const dependencyName = getDependencyName(name);

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

const potentialSolutions = `\n
const potentialSolutions = moduleName
? `\n
Potential solutions:
- Is ${moduleName} a valid NestJS module?
- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
@Module({
imports: [ /* the Module containing ${dependencyName} */ ]
})
`
: `\n
Potential solutions:
- If ${dependencyName} is a provider, is it part of the current Module?
- If ${dependencyName} is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing ${dependencyName} */ ]
})
`;

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

if (isNil(index)) {
message += `. Please make sure that the "${key.toString()}" property is available in the current context.${potentialSolutions}`;
return message;
Expand Down

0 comments on commit 96e4e8d

Please sign in to comment.