question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NestJS fails silently on multi package repo.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sunnylqmcommented, Nov 20, 2019

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

1reaction
sudoJoecommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common errors - FAQ - A progressive Node.js framework
During your development with NestJS, you may encounter various errors as you learn the framework. "Cannot resolve dependency" error#. Probably the most common ......
Read more >
Nestjs Start Fails Silently In Module Initialization - ADocLib
In terminal window 1, start by cloning the nestjs-package-starter repo. to ... NestJS fails silently on multi package repo. module) Nest fails silently, ......
Read more >
lint-staged - npm
For a given staged file, the closest configuration file will always be used. See "How to use lint-staged in a multi-package monorepo?
Read more >
NestJS Create Reusable/Publishable Library - Stack Overflow
js Package, so I can reuse a controller in multiple Nest.js projects. I have checked out library but that doesn't seem to be...
Read more >
Getting started with continuous integration for Nest.js APIs
After running the nest command, you will be prompted to choose a package manager. Select npm and press the Enter key to start...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found