nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.42k stars 2.34k forks source link

Cannot generate library with the @nx/react generator and rspack as a bundler #28378

Open guitarooman14 opened 14 hours ago

guitarooman14 commented 14 hours ago

Current Behavior

I was just following the new Rspack documentation to migrate my current project from Webpack to Rspack and I tried to create a new library with the following command provided by this doc (Using @nx/rspack) :

nx g @nx/react:lib my-lib --bundler=rspack

And this is what I got :

$ nx g @nx/react:lib my-lib --bundler=rspack

 NX  Generating @nx/react:library
 NX  Property 'bundler' does not match the schema. 'rspack' should be one of none,vite,rollup.

Expected Behavior

The new library or application should be created and configure to use the rspack bundler.

GitHub Repo

No response

Steps to Reproduce

For a fresh new install

  1. npx create-nx-workspace --bundler rspack
    • Where would you like to create your workspace? test_rspack
    • Which stack do you want to use? React
    • What framework would you like to use? None
    • Integrated monorepo, or standalone project? Integrated monorepo
    • Application name ? test_rspack
    • Which bundler would you like to use? Rspack
    • Test runner to use for end to end (E2E) tests ? None
    • Default stylesheet format ? css
    • Which CI provider would you like to use? Gitlab
  2. cd test_rspack
  3. nx g @nx/react:lib my-lib --bundler=rspack

Nx Report

Node : 20.11.1 OS : win32-x64 Native Target : x86_64-windows npm : 10.5.2

nx (global) : 20.0.0 nx : 20.0.0 @nx/js : 20.0.0 @nx/jest : 20.0.0 @nx/eslint : 20.0.0 @nx/workspace : 20.0.0 @nx/devkit : 20.0.0 @nx/eslint-plugin : 20.0.0 @nx/react : 20.0.0 @nx/rspack : 20.0.0 @nx/web : 20.0.0 typescript : 5.5.4

Registered Plugins: @nx/eslint/plugin @nx/jest/plugin

Failure Logs

No response

Package Manager Version

10.5.2

Operating System

Additional Information

No response

Coly010 commented 11 hours ago

The React Library Generator does not currently have rspack and option for bundler.

If your library is only going to be used internally in your workspace then you do not need to specify a bundler at all, and it will be bundled when the application is bundled.

guitarooman14 commented 10 hours ago

Actually, I'm migrating some libraries from a current NX repository to another one in order to expose them to others projects. Moreover the new repository will just have a showcase application in order to show how to use those libraries so It will be helpful to use the @nx/react generator with the rspack configuration.

I wanted to test rspack because this application will use the module federation feature and I already have been struggle with the webpack implementation.

And by the way, I was just following the @nx/rspack documentation. So if I follow what you say, the documentation is wrong.

Coly010 commented 10 hours ago

@guitarooman14 Indeed, the rspack documentation is incorrect. I'll update that to be correct.

The application can still use rspack and the libraries can use any bundler or no bundler.

When you say expose the libraries to other projects, do you mean via an npm package or via a Module Federation remote?

guitarooman14 commented 10 hours ago

I need to expose them via an npm package. Basically I want to create publishable libraries with Rspack.

Coly010 commented 10 hours ago

In that case, you can use vite or rollup or wait until we add rspack support for it :)

Thanks for raising this!