web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.8k stars 562 forks source link

Nestjs dependencies not being included in bundle #4319

Closed p-v-d-Veeken closed 10 months ago

p-v-d-Veeken commented 1 year ago

System Info

System: OS: macOS 13.5.1 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 440.11 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v18.17.1/bin/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm pnpm: 8.9.0 - ~/.nvm/versions/node/v18.17.1/bin/pnpm Watchman: 2023.08.07.00 - /usr/local/bin/watchman Browsers: Chrome: 117.0.5938.149 Safari: 16.6 npmPackages: @rspack/core: ~0.3.6 => 0.3.6 @rspack/dev-server: ~0.3.6 => 0.3.6 @rspack/plugin-minify: ~0.3.6 => 0.3.6

Details

I've set up a basic NestJS + RSPack repo and when building the app, the resulting main.js does not include the necessary @nestjs/* dependencies. This means, that the bundle can only be executed if the corresponding node_modules are available. Which kind of defeats the purpose of using a bundler.

Reproduce link

https://github.com/p-v-d-Veeken/nest-rspack

Reproduce Steps

  1. Clone this repo: https://github.com/p-v-d-Veeken/nest-rspack
  2. Run npm install
  3. Run nx build demo
  4. Run node dist/apps/demo/main.js this will output:
    [Nest] 14258  - 10/13/2023, 2:34:34 PM     LOG [NestFactory] Starting Nest application...
    [Nest] 14258  - 10/13/2023, 2:34:34 PM     LOG [InstanceLoader] AppModule dependencies initialized +14ms
    [Nest] 14258  - 10/13/2023, 2:34:34 PM     LOG [RoutesResolver] AppController {/api}: +20ms
    [Nest] 14258  - 10/13/2023, 2:34:34 PM     LOG [RouterExplorer] Mapped {/api, GET} route +3ms
    [Nest] 14258  - 10/13/2023, 2:34:34 PM     LOG [NestApplication] Nest application successfully started +3ms
    [Nest] 14258  - 10/13/2023, 2:34:34 PM     LOG 🚀 Application is running on: http://localhost:3000/api
  5. Run mv node_modules node_modules.tmp
  6. Run node dist/apps/demo/main.js again, this time it will output:
    
    /Users/user/code/nest-rspack/dist/apps/demo/main.js:721
            throw e;
            ^

Error: Cannot find module '@nestjs/common' Require stack:

hardfist commented 1 year ago

@antoinepairet seems bundle nestjs successfully, and we have an example https://github.com/web-infra-dev/rspack/blob/main/examples/nestjs/rspack.config.js which bundles most of the library in node_modules, but it seems there're still some problems with Nestjs itself and other library, I'm not sure whether it could bundle all third party libraries because it mostly depends on third party library implementation. so if you successfully bundle it with webpack and find problems on rspack, it's mostly rspack's bug | missing features, but if you can't bundle it successfully with webpack it may be not a easy rspack to do the same thing.

stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!