Skip to content

Commit

Permalink
fix: ignore the MF2 runtime warning (#821)
Browse files Browse the repository at this point in the history
* fix: ignore the MF2 runtime warning

* refactor: move to a private method

* chore: add changeset
  • Loading branch information
jbroma authored Dec 10, 2024
1 parent 39f80b3 commit 287991e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-dots-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Ignore irrelevant MF2 runtime warning about request of a dependency being an expression
26 changes: 23 additions & 3 deletions packages/repack/src/plugins/ModuleFederationPluginV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,35 @@ export class ModuleFederationPluginV2 implements RspackPluginInstance {
return adjustedSharedDependencies;
}

apply(compiler: Compiler) {
this.ensureModuleFederationPackageInstalled(compiler.context);

private setupIgnoredWarnings(compiler: Compiler) {
// MF2 produces warning about not supporting async await
// we can silence this warning since it works just fine
compiler.options.ignoreWarnings = compiler.options.ignoreWarnings ?? [];
compiler.options.ignoreWarnings.push(
(warning) => warning.name === 'EnvironmentNotSupportAsyncWarning'
);
// MF2 produces warning about dynamic import in loadEsmEntry but it's not relevant
// in RN env since we override the loadEntry logic through a hook
// https://github.com/module-federation/core/blob/fa7a0bd20eb64eccd6648fea340c6078a2268e39/packages/runtime/src/utils/load.ts#L28-L37
compiler.options.ignoreWarnings.push((warning) => {
// @ts-expect-error moduleDescriptor is present in the warning object
const modulePath = warning.moduleDescriptor.name;
const moduleName = '@module-federation/runtime/dist/index.cjs.js';
const isMF2Runtime = modulePath.endsWith(moduleName);
const requestExpressionWarning =
/Critical dependency: the request of a dependency is an expression/;

if (isMF2Runtime && requestExpressionWarning.test(warning.message)) {
return true;
}

return false;
});
}

apply(compiler: Compiler) {
this.ensureModuleFederationPackageInstalled(compiler.context);
this.setupIgnoredWarnings(compiler);

const ModuleFederationPlugin = this.getModuleFederationPlugin(compiler);

Expand Down

0 comments on commit 287991e

Please sign in to comment.