-
Notifications
You must be signed in to change notification settings - Fork 2.5k
NX + NestJS + webpack -> rspack = π€·ββοΈ #30292
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
Comments
@Coly010 @FrozenPandaz sorry for tagging, but I've had zero traction on my issues related to these matters (@nx/rspack), and this has been broken for our team since at least v. 20.2.2, locking our team's codebase to @nx/[email protected]. Can we at least get confirmation that this is a regression so we can start thinking about a path forward π? (also related, but closed since the interest appeared to die out: #29388, #29482) |
I will investigate this shortly and get it fixed. |
β¦ific and accurate closed #30292
Hey @rujorgensen thanks for the issue. You listed two generators but here are their use-cases
module.exports = composePlugins(
withNx(),
withReact()
);
I'll leave this open and attach the PR when it is handled. |
@ndcunningham Thanks, that sounds good :). We now get new issues when trying to migrate to the latest NX due to this, so it has become crucial for us to be able to generate a fresh working rspack configuration using the generator, allowing us to continue updating NX. What kind of timeline are we looking at--is it something that is being worked on now? Is there somewhere we can track? Just as a side comment on your second point; our current rspack configuration was generated on a webpack NestJS app, by using the NX generator, so the generator was working at some point during the past 1-2 years or so, and our repo is similar regarding executors, to the reproduction repo I posted here. |
|
@ndcunningham I took a closer look at the second part of your comment regarding the targets, and the configuration actually looks different compared to the configuration we have in our mono repo (which initiated this entire chase). I tried generating a fresh repository with a non-inferred (explicit?) target using the @nx/rspack:application generator, but without luck. I opened a new issue here #31204 (comment). It would be incredibly helpful if I could just get a quick yes/no answer to the question: |
OK good news. I think I managed to end up with a minimal working setup. I still think there are issues, this time in the NxAppRspackPlugin, as it appears to be stripping data off the I made a wrapper around the plugin to make it work temporarily: const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
const rspack = require('@rspack/core');
const { join } = require('path');
/**
* NxAppRspackPlugin appears to be altering the compiler.options, removing eg. the optimization object.
*/
class CustomNxAppRspackPlugin extends NxAppRspackPlugin {
apply(compiler) {
const orignalOptions = structuredClone(compiler.options.optimization);
if (compiler.options.optimization) {
console.log('Applying CustomNxAppRspackPlugin, compiler.options.optimization there');
}
super.apply(compiler);
if (!compiler.options.optimization) {
console.log('CustomNxAppRspackPlugin applied, compiler.options.optimization now gone, re-appply');
compiler.options.optimization = orignalOptions;
}
}
}
module.exports = {
output: {
path: join(__dirname, '../../dist/apps/nestjs-rspack'),
},
// π¨ πππ I added this to the standard configuration generated by NX
entry: {},
// π¨ πππ I added this to the standard configuration generated by NX
optimization: {
// π¨ πππ I added this to the standard configuration generated by NX, as it appears to be necessary (see screenshot below)
removeAvailableModules: true,
// π¨ πππ I added this to the standard configuration generated by NX, as it appears to be necessary (see screenshot below)
minimizer: [
new rspack.SwcJsMinimizerRspackPlugin({
minimizerOptions: {
// We need to disable mangling and compression for class names and function names for Nest.js to work properly
// The execution context class returns a reference to the class/handler function, which is for example used for applying metadata using decorators
// https://docs.nestjs.com/fundamentals/execution-context#executioncontext-class
compress: {
keep_classnames: true,
keep_fnames: true,
},
mangle: {
keep_classnames: true,
keep_fnames: true,
},
},
}),
],
},
plugins: [
// π¨ πππ I replaced NxAppRspackPlugin with a custom version, as it appears to strip off necessary build options
new CustomNxAppRspackPlugin({
// π¨ πππ I replaced NxAppRspackPlugin with a custom version, as it appears to strip off necessary build options
target: 'node',
tsConfig: 'apps/nestjs-rspack/tsconfig.app.json',
main: 'apps/nestjs-rspack/src/main.ts',
outputHashing: 'none',
}),
],
}; Here is a full minimal repo: https://github.com/rujorgensen/nx-nestjs-rspack-working. I will try to apply this configuration to our setup, and see how far it gets me this time. (edit: we now have a working main repo π) |
Yup, looks like that line is causing the issue. Let's see if my PR gets accepted. It's a very small change... |
Uh oh!
There was an error while loading. Please reload this page.
Current Behavior
Neither of the generators @nx/rspack:convert-config-to-rspack-plugin or @nx/rspack:convert-webpack converts the webpack configuration of a NestJS application to rspack.
Expected Behavior
I'd expect:
GitHub Repo
https://github.com/rujorgensen/nx-webpack-rspack-conf-issue
Steps to Reproduce
a. npx nx g @nx/rspack:convert-webpack --project=nx-workspace
--OR--
b. npx nx g @nx/rspack:convert-config-to-rspack-plugin --project=nx-workspace
Current result:
3.a. Completes without touching any files
3.b. Fails with "NX Could not find any projects to migrate."
Nx Report
Failure Logs
Package Manager Version
pnpm v. 9.10.0
Operating System
Additional Information
(re-opening closed issue #29482)
The text was updated successfully, but these errors were encountered: