Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@nx/rspack withNx, withReact, and withWeb are all broken with current nx add command #408

Open
helgardferreira opened this issue Jul 7, 2024 · 0 comments

Comments

@helgardferreira
Copy link

Current Behavior

If you follow the current @nx/rspack documentation, it's stated that users should execute nx add @nx/rspack to Add Rspack to an existing workspace. However, if you execute nx add @nx/rspack without NX_ADD_PLUGINS=false, then a "crystal" plugin setup will be generated in the user's nx.json file like so:

"plugins": [
  {
    "plugin": "@nx/rspack/plugin",
    "options": {
      "buildTargetName": "build",
      "serveTargetName": "serve",
      "previewTargetName": "preview"
    }
  }
],

If a "crystal" plugin setup for @nx/rspack is located in a user's nx.json file then the current implementations of withNx, withReact, and withWeb are guaranteed to fail since they assume context.projectGraph is defined - which it won't be for the initial run of composePlugins's combined function since composePlugin is invoked (indirectly) by readRspackOptions not runExecutor. In other words, withNx, withReact, and withWeb do not have a check for process.env['NX_TASK_TARGET_PROJECT'] to ensure that context.projectGraph is defined by runExecutor.

Expected Behavior

Either:

  • The @nx/rspack documentation should be updated as to not mention nx add @nx/rspack (not great)
  • The @nx/rspack generators should be updated to prevent updating the nx.json file (okayish)
  • The implementations for withNx, withReact, and withWeb should add a basic check for process.env['NX_TASK_TARGET_PROJECT'] and skip their steps until it is safe to do so (better)
  • The implementations for withNx, withReact, and withWeb should be updated to complete the crystal plugin integration (best)

Proposed Solution

Honestly, the quickest fix for the time being (until the crystal plugin integration is done) would be to something like this to withNx, withReact, and withWeb:

if (!process.env['NX_TASK_TARGET_PROJECT']) {
  return Object.assign({}, config)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant