Skip to content

Conversation

ScriptedAlchemy
Copy link
Member

Description

The _handleContainerModule method from packages/manifest/src/ModuleHandler.ts calls split(' ') on the module's identifier which breaks if the path or expose key contain spaces or other special characters.

Image

Here's a an example of a problematic identifier (see the import path for the Button expose):

container entry (default) [["./Button",{"import":["./src/path with spaces/Button.tsx"],"name": "__federation_expose_Button"}]]

Related Issue

#2684

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

Copy link

changeset-bot bot commented Sep 19, 2025

⚠️ No Changeset found

Latest commit: 3e797c9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Sep 19, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 3e797c9
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/68d48c3a4ef25e0008bca118
😎 Deploy Preview https://deploy-preview-4083--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ScriptedAlchemy
Copy link
Member Author

@codex see if there is a better way to fix this issue / the root cause of the problem presented here that cuases the need for this kind of fix in the first place.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 299 to 315
try {
// Prefer parsing exposes from stats first
entries = JSON.parse(data[3]);
} catch {
// If that fails, fallback to the original options
const exposes = this._options.exposes;

if (!exposes || typeof exposes !== 'object') {
return;
}

entries = Object.entries(exposes);
}

entries.forEach(([prefixedName, file]) => {
// TODO: support multiple import
exposesMap[getFileNameWithOutExt(file.import[0])] = getExposeItem({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Normalize fallback exposes before accessing import

When JSON parsing of identifier fails, the code falls back to this._options.exposes and iterates the entries assuming each value already looks like { import: [...] }. For typical module federation configs the values are plain strings (e.g. exposes: { './foo': './foo.js' }), so file is a string and file.import[0] throws, causing the Stats plugin to crash in the same spaces-in-path scenario this change is supposed to fix. The fallback needs to normalize string/array expose definitions into an object with an import array (or skip them) before dereferencing file.import.

Useful? React with 👍 / 👎.

Copy link

Summary

Testing

  • pnpm exec jest --config packages/manifest/jest.config.js

View task →

@ScriptedAlchemy
Copy link
Member Author

@vinicius-at-webflow hows this?

@vinicius-at-webflow
Copy link
Contributor

@2heal1 I see you went for an unified approach instead of the fallback one, keeping the JSON.parse but no split(' '). Much safer 💯. I tested manually with my repro repo and it is working now! 👏

@ScriptedAlchemy
Copy link
Member Author

Still a workaround but should buy time till we can rewrite this. Pulling data from the stats at all is very slow. Considering we more recently added "communication hooks" to federation, we actually know what modules are registered at a high level. So we should loop over a set of known modules to extract data instead of serializing the whole graph in stats to pull the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants