angular-architects / module-federation-plugin

MIT License
735 stars 203 forks source link

Build failure with native federation in Angular 18 #683

Open sajay-g opened 2 weeks ago

sajay-g commented 2 weeks ago

With what library do you have an issue?

native-federation

Reproduction of the bug/regression with instructions

StckBlitz

npm run start

Expected behavior

Build successfully by ignoring the packages mentioned in skip section of federated-config.js

Versions of Native/Module Federation, Angular, Node, Browser, and operating system

Native Federation: 18.2.2 Angular: 18.2.0 Node: >18.9 Browser: Chrome OS: Mac 14.5 (23F79) Sonoma

Other information

Previously Reported Similar Issue

Console Log

> ng serve
 INFO  Building federation artefacts
 INFO  Preparing shared npm packages
 NOTE  This only needs to be done once, as results are cached
 NOTE  Skip packages you don't want to share in your federation config
✘ [ERROR] Could not resolve "@graphql-tools/schema"

    node_modules/@apollo/client/testing/experimental/createTestSchema.js:2:37:
      2 │ import { addResolversToSchema } from "@graphql-tools/schema";
        ╵                                      ~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@graphql-tools/schema" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

1 of 14 errors shown (disable the message limit with --log-limit=0)
 ERR!  Error bundling shared npm package 
 ERR!  Build failed with 14 errors:
 ERR!  node_modules/@apollo/client/react/ssr/getDataFromTree.js:5:37: ERROR: Could not resolve "react-dom/server"
 ERR!  node_modules/@apollo/client/react/ssr/renderToStringWithData.js:2:31: ERROR: Could not resolve "react-dom/server"
 ERR!  node_modules/@apollo/client/testing/experimental/createTestSchema.js:2:37: ERROR: Could not resolve "@graphql-tools/schema"
 ERR!  node_modules/@apollo/client/testing/experimental/createTestSchema.js:3:31: ERROR: Could not resolve "@graphql-tools/merge"
 ERR!  node_modules/@apollo/client/testing/experimental/graphql-tools/utils.js:4:56: ERROR: Could not resolve "@graphql-tools/utils"
 ERR!  ...
 ERR!  For more information, run in verbose mode
 NOTE  
 NOTE  
 NOTE  ** Important Information: ***
 NOTE  The error message above shows an issue with bundling a node_module.
 NOTE  In most cases this is because you (indirectly) shared a Node.js package,
 NOTE  while Native Federation builds for the browser.
 NOTE  You can move such packages into devDependencies or skip them in your federation.config.js.
 NOTE  
 NOTE  More Details: https://bit.ly/nf-issue
 NOTE  
 NOTE  

I would be willing to submit a PR to fix this issue