diff --git a/.circleci/config.yml b/.circleci/config.yml index 39f4ba36504..fb9ae8e5ed5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/integration/injector/e2e/optional-factory-provider-dep.spec.ts b/integration/injector/e2e/optional-factory-provider-dep.spec.ts index 530db528613..d82f05136d4 100644 --- a/integration/injector/e2e/optional-factory-provider-dep.spec.ts +++ b/integration/injector/e2e/optional-factory-provider-dep.spec.ts @@ -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({ diff --git a/packages/core/errors/messages.ts b/packages/core/errors/messages.ts index 2d327280ef6..62aa6b0b22c 100644 --- a/packages/core/errors/messages.ts +++ b/packages/core/errors/messages.ts @@ -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; @@ -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; diff --git a/packages/core/test/errors/test/messages.spec.ts b/packages/core/test/errors/test/messages.spec.ts index 077f0b5cdba..cbc3e15bdb3 100644 --- a/packages/core/test/errors/test/messages.spec.ts +++ b/packages/core/test/errors/test/messages.spec.ts @@ -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 */ ] }) @@ -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 */ ] }) @@ -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 */ ] }) @@ -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 */ ] }) @@ -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({ @@ -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 */ ] }) @@ -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 */ ] })