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

withModuleFederation plugin overwrites config.optimization options #27201

Closed
1 of 4 tasks
grigorigoldman opened this issue Jul 30, 2024 · 1 comment · Fixed by #27376
Closed
1 of 4 tasks

withModuleFederation plugin overwrites config.optimization options #27201

grigorigoldman opened this issue Jul 30, 2024 · 1 comment · Fixed by #27376
Assignees
Labels
outdated scope: module federation Issues related to module federation support type: bug

Comments

@grigorigoldman
Copy link

Current Behavior

I'm using NX-enhanced webpack plugins as per documentation to configure react and module federation, e.g.

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

export default composePlugins(
  withNx(),
  withReact(),
  withModuleFederation(config)
}

I have noticed that the optimization options are lost when withModuleFederation is invoked, e.g. when I do this:

export default composePlugins(
  withNx(),
  withReact(),
  (config) => {
    console.log({ optimization: config.optimization });
    return config;
  },
  withModuleFederation(config),
  (config) => {
    console.log({ optimization: config.optimization });
    return config;
  }
}

These are the config options before:

optimization: {
  sideEffects: true,
  minimize: false,
  minimizer: [Array],
  runtimeChunk: [Object],
  concatenateModules: true,
  emitOnErrors: false,
  moduleIds: 'deterministic',
  splitChunks: [Object]
}

and this is after:

optimization: {
  runtimeChunk: false
},

This is causing problems for me later on:

ERROR in main.js
main.js from Terser plugin
"Import" statement may only appear at the top level [main.js:12,0]
    at js_error (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:536:11)
    at TreeWalker.visit (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:11818:13)
    at TreeWalker._visit (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:6728:24)
    at AST_Import._walk (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:5122:28)
    at walk_body (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:3869:17)
    at AST_Function.<anonymous> (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:4368:17)
    at /Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:6729:21
    at TreeWalker.visit (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:11720:13)
    at TreeWalker._visit (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:6728:24)
    at AST_Function._walk (/Users/xxxx/workspace/xxxx/node_modules/terser/dist/bundle.min.js:4362:28)

Expected Behavior

I was expecting optimization options to be unchanged when withModuleFederation plugin is used.

GitHub Repo

No response

Steps to Reproduce

  1. Enable withNx, withReact, and withModuleFederation plugins
  2. Optimization options after withModuleFederation will not have all of the default values

Nx Report

NX   Report complete - copy this into the issue template

Node   : 18.18.0
OS     : darwin-x64
yarn   : 1.22.22

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

Failure Logs

No response

Package Manager Version

1.22.22

Operating System

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

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: module federation Issues related to module federation support label Aug 9, 2024
Coly010 added a commit that referenced this issue Aug 12, 2024
Coly010 added a commit that referenced this issue Aug 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…#27376)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
`withModuleFederation` is overwriting `config.optimization` rather than
merging it.


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
`config.optimization` should be merged

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #27201
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 Sep 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: module federation Issues related to module federation support type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants