Skip to content

Commit 287991e

Browse files
authored
fix: ignore the MF2 runtime warning (#821)
* fix: ignore the MF2 runtime warning * refactor: move to a private method * chore: add changeset
1 parent 39f80b3 commit 287991e

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

.changeset/healthy-dots-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack": patch
3+
---
4+
5+
Ignore irrelevant MF2 runtime warning about request of a dependency being an expression

packages/repack/src/plugins/ModuleFederationPluginV2.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,35 @@ export class ModuleFederationPluginV2 implements RspackPluginInstance {
233233
return adjustedSharedDependencies;
234234
}
235235

236-
apply(compiler: Compiler) {
237-
this.ensureModuleFederationPackageInstalled(compiler.context);
238-
236+
private setupIgnoredWarnings(compiler: Compiler) {
239237
// MF2 produces warning about not supporting async await
240238
// we can silence this warning since it works just fine
241239
compiler.options.ignoreWarnings = compiler.options.ignoreWarnings ?? [];
242240
compiler.options.ignoreWarnings.push(
243241
(warning) => warning.name === 'EnvironmentNotSupportAsyncWarning'
244242
);
243+
// MF2 produces warning about dynamic import in loadEsmEntry but it's not relevant
244+
// in RN env since we override the loadEntry logic through a hook
245+
// https://github.com/module-federation/core/blob/fa7a0bd20eb64eccd6648fea340c6078a2268e39/packages/runtime/src/utils/load.ts#L28-L37
246+
compiler.options.ignoreWarnings.push((warning) => {
247+
// @ts-expect-error moduleDescriptor is present in the warning object
248+
const modulePath = warning.moduleDescriptor.name;
249+
const moduleName = '@module-federation/runtime/dist/index.cjs.js';
250+
const isMF2Runtime = modulePath.endsWith(moduleName);
251+
const requestExpressionWarning =
252+
/Critical dependency: the request of a dependency is an expression/;
253+
254+
if (isMF2Runtime && requestExpressionWarning.test(warning.message)) {
255+
return true;
256+
}
257+
258+
return false;
259+
});
260+
}
261+
262+
apply(compiler: Compiler) {
263+
this.ensureModuleFederationPackageInstalled(compiler.context);
264+
this.setupIgnoredWarnings(compiler);
245265

246266
const ModuleFederationPlugin = this.getModuleFederationPlugin(compiler);
247267

0 commit comments

Comments
 (0)