-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 20.2.1, Newly created react-monorepo & module federation setup doesn't work #29269
Comments
The tl;dr is I suspect This is a similar issue for me, except I did an update to cause it, rather than fresh install. Working at the start
Did a
Tried with 20.2.0 (I didn't try 20.2.1 since the above is with that) and 20.3.0-beta.0 and the same issue on those builds too This might be useful import { composePlugins, withNx, withReact } from '@nx/rspack';
import {
withModuleFederation,
ModuleFederationConfig,
} from '@nx/rspack/module-federation';
import baseConfig from './module-federation.config';
const config: ModuleFederationConfig = {
...baseConfig,
};
// Nx plugins for rspack to build config object from Nx options and context.
/**
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
* The DTS Plugin can be enabled by setting dts: true
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
*/
export default composePlugins(
withNx(),
withReact(),
withModuleFederation(config, { dts: false }),
(config) => {
config.devServer = {
allowedHosts: 'all',
}
if (config.module?.rules) {
config.module.rules = config.module.rules.filter(r => r.test.toString() !== '/\\.svg$/');
}
config.module?.rules?.push({
test: /\.svg$/,
issuer: /\.[jt]sx?$/,
use: [
{
loader: require.resolve('@svgr/webpack'),
options: {
exportType: 'named',
namedExport: 'ReactComponent',
},
},
],
});
return config;
}
); and after change import { ModuleFederationConfig } from '@nx/module-federation';
import { composePlugins, withNx, withReact } from '@nx/rspack';
import { withModuleFederation } from '@nx/module-federation/rspack';
import baseConfig from './module-federation.config';
const config: ModuleFederationConfig = {
...baseConfig,
};
// Nx plugins for rspack to build config object from Nx options and context.
/**
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
* The DTS Plugin can be enabled by setting dts: true
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
*/
export default composePlugins(
withNx(),
withReact(),
withModuleFederation(config, { dts: false }),
(config) => {
config.devServer = {
allowedHosts: 'all',
};
if (config.module?.rules) {
config.module.rules = config.module.rules.filter(
(r) => r.test.toString() !== '/\\.svg$/',
);
}
config.module?.rules?.push({
test: /\.svg$/,
issuer: /\.[jt]sx?$/,
use: [
{
loader: require.resolve('@svgr/webpack'),
options: {
exportType: 'named',
namedExport: 'ReactComponent',
},
},
],
});
return config;
},
); |
@bigfish This seems like a package resolution issue. The We can ensure it gets installed at the package root though when running the generators. @rmaclean Same as above. That package should have been resolved by your package manager. Rolling back the import makes sense if you also roll back the versions of the packages you're using, but moving forward, the import should be I'll update the generators and the migrations to forcibly install the package. |
…lled for users (#29416) ## Current Behavior The `@nx/module-federation` package is a direct dependency of some of the other packages in the Nx Plugin ecosystem. It should be resolved correctly by package managers such that it can be used when setting up MF projects. However, some users are facing issues with module resolutions where the package is not found as expected. ## Expected Behavior Install the package directly for the user to ensure module resolution works as expected. ## Related Issue(s) Fixes #29269
…lled for users (#29416) ## Current Behavior The `@nx/module-federation` package is a direct dependency of some of the other packages in the Nx Plugin ecosystem. It should be resolved correctly by package managers such that it can be used when setting up MF projects. However, some users are facing issues with module resolutions where the package is not found as expected. ## Expected Behavior Install the package directly for the user to ensure module resolution works as expected. ## Related Issue(s) Fixes #29269
Current Behavior
npx create-nx-workspace react-monorepo --preset=react-monorepo --pm=pnpm
then choose:
app name = my-app
bundler = rspack
test runner = none
stylesheet = CSS
CI = later
cacheing = no
cd react-monorepo
pnpm nx g @nx/react:host shell --remotes=remote --bundler=rspack
stylesheet = css
e2e = none
succeeds
nx serve shell
FAILS with error:
NX Remote failed to start. A complete log can be found in: /Volumes/Code/react-monorepo/.nx/workspace-data/2024-12-09T15_30_47_332Z-build.log
LOG
So it looks like it's just missing '@nx/module-federation/rspack' package, so I triied to install it, but that didn't work. Realiized I need just @nx/module-federation so installed that, and now it works.
So I think the generators need to be updated to install this package.
Expected Behavior
Shell app is served with remotes.
GitHub Repo
No response
Steps to Reproduce
npx create-nx-workspace react-monorepo --preset=react-monorepo --pm=pnpm
then choose:
app name = my-app
bundler = rspack
test runner = none
stylesheet = CSS
CI = later
cacheing = no
cd react-monorepo
pnpm nx g @nx/react:host shell --remotes=remote --bundler=rspack
stylesheet = css
e2e = none
succeeds
nx serve shell
FAILS with error:
NX Remote failed to start. A complete log can be found in: /Volumes/Code/react-monorepo/.nx/workspace-data/2024-12-09T15_30_47_332Z-build.log
LOG
So it looks like it's just missing '@nx/module-federation/rspack' package, so I triied to install it, but that didn't work. Realiized I need just @nx/module-federation so installed that, and now it works.
So I think the generators need to be updated to install this package.
Nx Report
Failure Logs
NX Cannot find module '@nx/module-federation/rspack' Require stack: - /Volumes/Code/react-monorepo/remote/rspack.config.ts - /Volumes/Code/react-monorepo/remote/rspack.config.prod.ts - /Volumes/Code/react-monorepo/node_modules/.pnpm/@nx+rspack@20.2.1_@module-federation+enhanced@0.7.6_@module-federation+node@2.6.11_@swc-node+_vvolop54a2iqvroiphed6tvd2q/node_modules/@nx/rspack/src/utils/resolve-user-defined-rspack-config.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/@nx+rspack@20.2.1_@module-federation+enhanced@0.7.6_@module-federation+node@2.6.11_@swc-node+_vvolop54a2iqvroiphed6tvd2q/node_modules/@nx/rspack/src/executors/rspack/lib/config.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/@nx+rspack@20.2.1_@module-federation+enhanced@0.7.6_@module-federation+node@2.6.11_@swc-node+_vvolop54a2iqvroiphed6tvd2q/node_modules/@nx/rspack/src/utils/create-compiler.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/@nx+rspack@20.2.1_@module-federation+enhanced@0.7.6_@module-federation+node@2.6.11_@swc-node+_vvolop54a2iqvroiphed6tvd2q/node_modules/@nx/rspack/src/executors/rspack/rspack.impl.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/config/schema-utils.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/command-line/run/executor-utils.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/devkit-internals.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/utils/assert-workspace-validity.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/project-graph/build-project-graph.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/project-graph/project-graph.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/project-graph/file-utils.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/utils/package-manager.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/utils/package-json.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/utils/print-help.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/src/command-line/run/run.js - /Volumes/Code/react-monorepo/node_modules/.pnpm/nx@20.2.1_@swc-node+register@1.9.2_@swc+core@1.5.29/node_modules/nx/bin/run-executor.js Pass --verbose to see the stacktrace.
Package Manager Version
pnpm 8.10.2
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: