Skip to content

@nestjs/terminus cannot be embedded in a webpack bundle #1423

@linsolas

Description

@linsolas

I'm submitting a...


[ ] Regression 
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Hello,

I'm developing several Nestjs applications, and for deployment purposes, I generally bundle the whole application into one single JS file, using webpack (through the command nest build --webpack).

My first problem is due to the require(``${module}``) statement in checkPackage.util.ts. In front of such statement, Webpack tries to embed all resources from the sames directory, which includes .d.ts files (such as node_modules/@nestjs/terminus/dist/lib/utils/checkPackage.d.ts. And then it fails saying:

ERROR in ./node_modules/@nestjs/terminus/dist/utils/checkPackage.util.d.ts 13:7
Module parse failed: Unexpected token (13:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| * checkPackages(['process', 'no_package'], 'TEST')
| */
export declare function checkPackages(packageNames: string[], reason: string): any[];
|

It can be avoided by overriding the default webpack.config.js with something like this:

module.exports = function (options) {
  const outputDirname = path.dirname(options.output.filename);
  // Ignore `.d.ts` files...
  options.module.rules.push({
    test: /\.d\.ts$/,
    use: 'null-loader',
  });
  ...

So now I can build my application... But it does not run anymore, because on runtime, @nestjs/terminus tries to load these dependencies from an inexistent node_modules directory.

[Nest] 12465 - 09/21/2021, 11:23:50 AM ERROR [PackageLoader] The "@nestjs/typeorm", "typeorm" packages are missing. Please, make sure to install the libraries ($ npm install @nestjs/typeorm typeorm) to take advantage of TypeOrmHealthIndicator.

Expected behavior

I would like to embed the @nestjs/terminus module in my application built with webpack. I would like to be able to skip these pre-checks by Terminus with an option, so Terminus will not throw this exception and quits.

What is the motivation / use case for changing the behavior?

To use @nestjs/terminus in my Nestjs application built with webpack.

Environment


Nest version: 8.0.6

 
For Tooling issues:
- Node version: v12
- Platform:  Windows / Linux 


Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions