Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- checkout
- run:
name: Update NPM version
command: 'sudo npm install -g npm@latest'
command: 'sudo npm install -g npm@^8'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('Optional factory provider deps', () => {
.equal(`Nest can't resolve dependencies of the POSSIBLY_MISSING_DEP (?). Please make sure that the argument MISSING_DEP at index [0] is available in the RootTestModule context.

Potential solutions:
- Is RootTestModule a valid NestJS module?
- If MISSING_DEP is a provider, is it part of the current RootTestModule?
- If MISSING_DEP is exported from a separate @Module, is that module imported within RootTestModule?
@Module({
Expand Down
24 changes: 17 additions & 7 deletions packages/core/errors/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,32 @@ export const UNKNOWN_DEPENDENCIES_MESSAGE = (
dependencies,
key,
} = unknownDependencyContext;
const moduleName = getModuleName(module) || 'Module';
const moduleName = getModuleName(module);
const dependencyName = getDependencyName(name);

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

const potentialSolutions = `\n
const potentialSolutions =
// If module's name is well defined
moduleName !== 'current'
? `\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 All @@ -83,9 +95,7 @@ Potential solutions:

message += ` (`;
message += dependenciesName.join(', ');
message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${getModuleName(
module,
)} context.`;
message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${moduleName} context.`;
message += potentialSolutions;

return message;
Expand Down
25 changes: 13 additions & 12 deletions packages/core/test/errors/test/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('Error Messages', () => {
stringCleaner(`Nest can't resolve dependencies of the CatService (?, CatService). Please make sure that the argument dependency at index [0] is available in the current context.

Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Expand All @@ -41,8 +41,8 @@ describe('Error Messages', () => {
stringCleaner(`Nest can't resolve dependencies of the CatService (?, MY_TOKEN). Please make sure that the argument dependency at index [0] is available in the current context.

Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Expand All @@ -62,8 +62,8 @@ describe('Error Messages', () => {
stringCleaner(`Nest can't resolve dependencies of the CatService (?, CatFunction). Please make sure that the argument dependency at index [0] is available in the current context.

Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Expand All @@ -83,8 +83,8 @@ describe('Error Messages', () => {
stringCleaner(`Nest can't resolve dependencies of the CatService (?, +). Please make sure that the argument dependency at index [0] is available in the current context.

Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Expand All @@ -104,6 +104,7 @@ describe('Error Messages', () => {
stringCleaner(`Nest can't resolve dependencies of the CatService (?, MY_TOKEN). Please make sure that the argument dependency at index [0] is available in the TestModule context.

Potential solutions:
- Is TestModule a valid NestJS module?
- If dependency is a provider, is it part of the current TestModule?
- If dependency is exported from a separate @Module, is that module imported within TestModule?
@Module({
Expand Down Expand Up @@ -137,8 +138,8 @@ describe('Error Messages', () => {
stringCleaner(`Nest can't resolve dependencies of the Symbol(CatProvider) (?). Please make sure that the argument dependency at index [0] is available in the current context.

Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Expand All @@ -158,8 +159,8 @@ describe('Error Messages', () => {
stringCleaner(`Nest can't resolve dependencies of the CatProvider (?, Symbol(DogProvider)). Please make sure that the argument dependency at index [0] is available in the current context.

Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Expand Down