NestJS fails silently on multi package repo.
See original GitHub issueBug Report
Current behavior
When creating my application module with NestFactory.createApplicationContext(), if something goes wrong (i.e. we forgot to include a mandatory provider for the module) Nest fails silently, without throwing an exception or showing an error message, which makes it hard to debug.
I checked #287, #1959, and #2377 that were similar but didn’t seem to solve the issue.
Input Code
I tried reproducing the issue using the samples, but in that case it seemed to be working OK. I wasn’t sure if my mono repo configuration was to blame for the issue so, I butchered my repo a bit to show the error.
Please check: https://github.com/alexmantaut/nets-js-silent-fail-issue
To debug run: ./packages/sls-random/src/index.ts Also, I attached vscode debug configuration.
The important part:
console.log('Start')
try {
const app = await NestFactory.createApplicationContext(MonitorModule, {})
} catch (error) {
console.log('Error', error)
}
console.log('success')
When I debug I only get the start message and then my application ends. Using vscode I can see that there is an exception, but then the program stops.
Exception:
lookupComponentInExports (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:183)
_tickCallback (next_tick.js:188)
Module.runMain (module.js:695)
startup (bootstrap_node.js:188)
(anonymous function) (bootstrap_node.js:609)
[ async function ]
lookupComponentInExports (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:186)
scanInExports (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:177)
lookupComponent (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:178)
resolveComponentInstance (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:143)
resolveSingleParam (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:132)
resolveParam (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:96)
resolveConstructorParams (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:112)
loadInstance (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:78)
loadProvider (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:35)
lookupComponentInImports (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:213)
lookupComponentInExports (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:181)
scanInExports (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:177)
lookupComponent (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:178)
resolveComponentInstance (/home/alexm/project_tmp/nest_silent_fail/packages/sls-random/node_modules/@nestjs/core/injector/injector.js:143)
Expected behavior
I would expect to get either an exception or an error message.
Possible Solution
Having NestFactory.createApplicationContext() throw an exception would be ideal for me, but any sort of error reporting would be useful in this case.
Environment
Nest version: 6.5.3
For Tooling issues:
- Node version: v8.16.0
- Platform: Ubuntu 18.04
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (2 by maintainers)
It failed silently because you are using a custom logger and
disabled the built in logger
. It failed when initializing and can not survive to reach the custom loggerSorry for taking so long to get back to you, I’m spread pretty thin right now, and that my suggestion wasn’t helpful.
I found this issue searching for clues to a completely unrelated error, but I’m going to clone your repo and see if I can reproduce it at home and go from there. I’ll let you know what I find out.