nest-modules / ioredis

:see_no_evil: :hear_no_evil: :speak_no_evil: A ioredis module for Nest framework (node.js)
MIT License
145 stars 31 forks source link

@nestjs/terminus module cannot be bundled #285

Open azaelvaldo opened 4 months ago

azaelvaldo commented 4 months ago

When I am building a bundled Webpack from my NestJS application, I get this error:

ERROR in ./node_modules/@nestjs/terminus/dist/utils/checkPackage.util.js.map 1:10 Module parse failed: Unexpected token (1:10)

I am not using any feature from HealthCheck included by default in the module. Is it possible to create a module without the HealthCheck module that uses terminus?

Related error and not solved: https://github.com/nestjs/terminus/issues/1423

focux commented 4 months ago

I'm experiencing the same problem, did you figure out a fix?

azaelvaldo commented 4 months ago

I had to clone the module repo and remove the whole feature that implements terminus, then manually added the module to my project without npm, like an own module.

kachalovsky commented 2 months ago

I faced the same issue.

If you are building an application using Webpack and do not require the health check feature, you can simply mock @nestjs/terminus in the bundle by updating your webpack.config.js file. This approach worked perfectly for me without any errors.

While the solution is not ideal, it serves as a temporary fix, and I hope a cleaner solution will be available in the future.

mock-terminus.js

module.exports = {
    HealthCheckService: class {},
    TerminusModule: class {},
    HealthIndicator: class {},
};

webpack.config.js

    {
        ...
        plugins: [
            ...options.plugins,
            new webpack.NormalModuleReplacementPlugin(
                /@nestjs\/terminus/,
                path.resolve(__dirname, 'mock-terminus.js'), // Replace @nestjs/terminus with mock
            ),
        ],
        ...
    }