diff --git a/.changeset/fair-plums-live.md b/.changeset/fair-plums-live.md new file mode 100644 index 0000000000..d03d1c7b0d --- /dev/null +++ b/.changeset/fair-plums-live.md @@ -0,0 +1,5 @@ +--- +'@module-federation/dts-plugin': patch +--- + +fix(dts-plugin): hold the broker server if the remote not start locally diff --git a/packages/dts-plugin/src/server/DevServer.ts b/packages/dts-plugin/src/server/DevServer.ts index d4740d9a3f..8a235d43ac 100644 --- a/packages/dts-plugin/src/server/DevServer.ts +++ b/packages/dts-plugin/src/server/DevServer.ts @@ -314,8 +314,19 @@ export class ModuleFederationDevServer { 'warn', ); - this._subscriberWebsocketMap[identifier] && - this._subscriberWebsocketMap[identifier].close(); + this._subscriberWebsocketMap[identifier]?.close(); + delete this._subscriberWebsocketMap[identifier]; + }); + + this._subscriberWebsocketMap[identifier].on('error', (event) => { + if ('code' in event && event.code === 'ETIMEDOUT') { + fileLog( + `Can not connect ${JSON.stringify(remote)}, please make sure this remote is started locally.`, + MF_SERVER_IDENTIFIER, + 'warn', + ); + } + this._subscriberWebsocketMap[identifier]?.close(); delete this._subscriberWebsocketMap[identifier]; }); }