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 loading in multiple instances of packages and the shared function in webpack.config.js does nothing #26043

Closed
1 of 4 tasks
Aubrey-Russell opened this issue May 24, 2024 · 3 comments
Assignees
Labels
blocked: more info needed outdated scope: module federation Issues related to module federation support scope: react Issues related to React support for Nx stale type: bug

Comments

@Aubrey-Russell
Copy link

Current Behavior

image

The shared function in the webpack.config.js doesn't do anything:

`
import { composePlugins, withNx } from '@nx/webpack';
import { withReact } from '@nx/react';
import { withModuleFederation } from '@nx/react/module-federation';

import baseConfig from './module-federation.config';
const coreLibraries = new Set([
"test"
]);

const config = {
...baseConfig,
shared: (libraryName, defaultConfig) => {
console.log('libraryName:', libraryName);
throw new Error('shared');
// Returning false means the library is not shared.
return defaultConfig;
},
};

// Nx plugins for webpack to build config object from Nx options and context.
export default composePlugins(
withNx(),
withReact(),
withModuleFederation(config)
);
`

The shared function never does any console.log or hits the exception here.

There is no issue on standalone mode, only when ingesting remote federated modules from a shell is there a problem.

Expected Behavior

The shared function should get triggered and work to prevent duplicate packages

GitHub Repo

https://github.com/Aubrey-Russell/grommet-react-mfe-issue-example

Steps to Reproduce

  1. pnpm install
  2. pnpm nx serve shell
  3. look at console log
  4. Change shared function to return false.
  5. Change shared function to return defaultConfig.
  6. Has no effect on anything, even putting a while(true) or throw new Error has no effect.

Nx Report

Node   : 21.1.0
OS     : win32-x64
pnpm   : 9.1.0

nx                 : 19.1.0
@nx/js             : 19.1.0
@nx/jest           : 19.1.0
@nx/linter         : 19.1.0
@nx/eslint         : 19.1.0
@nx/workspace      : 19.1.0
@nx/devkit         : 19.1.0
@nx/eslint-plugin  : 19.1.0
@nx/react          : 19.1.0
@nrwl/tao          : 19.1.0
@nx/web            : 19.1.0
@nx/webpack        : 19.1.0
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin

PS C:\Users\aruss\source\repos\TME\gr

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@FrozenPandaz FrozenPandaz added scope: module federation Issues related to module federation support scope: react Issues related to React support for Nx labels May 27, 2024
@Coly010
Copy link
Contributor

Coly010 commented Jun 7, 2024

Hi @Aubrey-Russell

I cloned your repo and added a console.log() to the shell/webpack.config.ts file and can see logs appearing.
Check screenshots at bottom.

Can you provide more information about where you're changing the shared function?
image
image

Copy link

This issue has been automatically marked as stale because more information has not been provided within 7 days.
It will be closed in 21 days if no information is provided.
If information has been provided, please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: more info needed outdated scope: module federation Issues related to module federation support scope: react Issues related to React support for Nx stale type: bug
Projects
None yet
Development

No branches or pull requests

3 participants