Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestJS fails silently on multi package repo. #2702

Closed
alexmantaut opened this issue Aug 4, 2019 · 11 comments
Closed

NestJS fails silently on multi package repo. #2702

alexmantaut opened this issue Aug 4, 2019 · 11 comments

Comments

@alexmantaut
Copy link

alexmantaut commented Aug 4, 2019

Bug 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
@alexmantaut alexmantaut added the needs triage This issue has not been looked into label Aug 4, 2019
@alexmantaut
Copy link
Author

Hi @kamilmysliwiec, I am trying to deploy my app on aws lambdas (it works fine on my local environment, where everything is configured ok), and struggling to understand the problems that arise from the different environment because of the silent failures.

I know you dealt with similar issues in the past, can you give me some hints on how to debug the errors?

In addition to what I posted on the original issue, I also tried putting console.log() lines inside typeorm and tslib just to know what is going on, but I am a bit lost on where the error is happening. I spent the best part of 2 days trying to find the source of the problem already, and I haven't been able to get a good idea of what is failing.

Thanks for your patience,

@dsebastien
Copy link
Contributor

+1, I'm having a similar issue.
If I try to inject a service somewhere but forget to import the containing module, then Nest fails silently instead of letting me know about the unknown/not injectable element.

I've lost quite some time figuring out where the issue was.

On a side note, I've tried to use a Logger instance within the catch and then functions attached to my bootstrap() method, but it doesn't seem to be working.

@kamilmysliwiec kamilmysliwiec added type: help wanted 🙂 type: question 🙌 and removed needs triage This issue has not been looked into labels Aug 26, 2019
@liangjun-jiang
Copy link

I had the similar issue. When I looked at my tsconfig.json, I found I added something while trying something.

 "esModuleInterop": true,
 "incremental": true

after removed these two lines, my app works properly.

@sudoJoe
Copy link

sudoJoe commented Sep 21, 2019

try import 'loud-rejection/register' before your nestFactory and see if that catches an exception?

@alexmantaut
Copy link
Author

Hi guys, thanks for the answers.

@loftyet, I tried removing esModuleInterop (incremental was not set), and after getting the code to compile again, the problem still fails silently...

@sudogeek I tried adding that import, or getting the library with the require() syntax, but did not seem to make a difference...

I tested both things by removing an entity from the typeorm definitions of the module I am using, and it still failed silently... I get the impresion this is a bug on nestjs...

@sudoJoe
Copy link

sudoJoe commented Sep 26, 2019

Sorry 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.

@sunnylqm
Copy link

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 logger

@alexmantaut
Copy link
Author

Thanks @sunnylqm! I just checked and assigning the logger on creation time fixes the issue for me:

NestFactory.create(AppModule, { logger: console, });

Just a question, I checked my code and I haven't been able to find the point where the custom logger is set... How did you realise that the problem was the logger? What is the default behaviour for the logger?

@jsdevtom
Copy link

jsdevtom commented Feb 21, 2020

@sudoJoe This shows me the error thanks! Spoke too soon

@zachgoll
Copy link

I too had this issue. The NestJS documentation advises to add the following to the factory method:

const app = await NestFactory.create(ApplicationModule, {
  logger: false,
});

As mentioned above, if the Logger configuration fails, it will fail silently. I switched this configuration to have { logger: console } temporarily and the error was printed to the console.

@kamilmysliwiec
Copy link
Member

We don't advise to disable logging.

To disable logging, set the logger property to false in the (optional) Nest application options object passed as the second argument to the NestFactory.create() method.

It's information, not a recommendation.

@nestjs nestjs locked as off-topic and limited conversation to collaborators Mar 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants