nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.91k stars 7.55k forks source link

Issues when bundling a Nest.js application #3224

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hey guys, short question:

When bundling a simple application {wrapped with Nest.js application-context} with Parcel, I am getting the following issues:

🚨  /demo/node_modules/@nestjs/core/nest-application.js:14:110: Cannot resolve dependency '@nestjs/websockets/socket-module'
  12 | const nest_application_context_1 = require("./nest-application-context");
  13 | const routes_resolver_1 = require("./router/routes-resolver");
> 14 | const { SocketModule } = optional_require_1.optionalRequire('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
     |                                                                                                              ^
  15 | const { MicroservicesModule } = optional_require_1.optionalRequire('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module')

I prepared a sample-project to demonstrate this. Is there any way to avoid this with parcel-bundler? Am I missing some configuration?

https://github.com/Syy0n/nestjs-parcel-test

joeyslack commented 4 years ago

First of all, that's a Parcel issue, and I see you posted an issue in their github as well: https://github.com/parcel-bundler/parcel/issues/3151 There's no guarantee that nest would ever work with parcel, so that will be up to you to patch, or figure it out.

Second, why do you need parcel for nest? Parcel just wraps up assets and runs an express webserver. Nestjs already has all of that and way way more. Nestjs does everything parcel does out of the box, and way more. Why not run nestjs as intended?

ghost commented 4 years ago

Why was this issue closed? Without waiting for any feedback from my side? Really? This is ridiculous!

It seems that this is not a parcel problem. It is caused by a really bad structuring and modularization of this project and its dynamic dependencies inside. Even webpack cannot bundle an application context!

Have a look here: https://github.com/nestjs/nest/issues/1706

Please re-open this issue!

kamilmysliwiec commented 4 years ago

It's not a NestJS issue. I'd suggest reading this comment https://github.com/nestjs/nest/issues/1706#issuecomment-475859756

Also, bundling won't work with many other Node.js libraries (like mongodb or pg for postgres), so if you really want to bundle your code, you should have good knowledge & understanding on what's possible and what's not with these tools. Bundling front-end code is much easier because you never have to either access the file system dynamically or load native binaries. There are several workarounds to this issue, one of them is included in the NestJS CLI (when you use nest build), another one was shared here https://github.com/nestjs/nest/issues/1706#issuecomment-474514484. Using parcel doesn't make sense and I don't see any reason why we should keep tis issue opened.