diff --git a/.changeset/shaggy-flowers-cry.md b/.changeset/shaggy-flowers-cry.md
new file mode 100644
index 00000000000..81d0608025d
--- /dev/null
+++ b/.changeset/shaggy-flowers-cry.md
@@ -0,0 +1,7 @@
+---
+'@module-federation/error-codes': patch
+'@module-federation/enhanced': patch
+'@module-federation/sdk': patch
+---
+
+fix(enhanced): abort process if not find expose modules
diff --git a/apps/website-new/docs/en/guide/troubleshooting/_meta.json b/apps/website-new/docs/en/guide/troubleshooting/_meta.json
index 9958f93ebc8..33f7f1de891 100644
--- a/apps/website-new/docs/en/guide/troubleshooting/_meta.json
+++ b/apps/website-new/docs/en/guide/troubleshooting/_meta.json
@@ -6,6 +6,12 @@
"label": "Runtime",
"collapsed":true
},
+ {
+ "type": "dir",
+ "name": "build",
+ "label": "Build",
+ "collapsed":true
+ },
{
"type": "dir",
"name": "type",
diff --git a/apps/website-new/docs/en/guide/troubleshooting/build/BUILD-001.mdx b/apps/website-new/docs/en/guide/troubleshooting/build/BUILD-001.mdx
new file mode 100644
index 00000000000..7023a611215
--- /dev/null
+++ b/apps/website-new/docs/en/guide/troubleshooting/build/BUILD-001.mdx
@@ -0,0 +1,18 @@
+import ErrorCodeTitle from '@components/ErrorCodeTitle';
+
+
+
+## Reason
+
+The Expose module resource could not be found properly.
+
+There are two reasons for this problem:
+1. The exposeModules file path set by `exposes` is incorrect and points to a non-existent address.
+2. When using `Next.js` or other frameworks with built-in webpack, the webpack address used by MF is incorrect.
+
+## Solutions
+
+There are corresponding solutions for the reasons:
+
+1. Check whether the module file path corresponding to exposes is correct. Pay attention to the case here.
+2. Check whether FEDERATION_WEBPACK_PATH is consistent with the webpack address used by the framework. If not, you can check whether the dependency is installed normally, or set process.env.FEDERATION_WEBPACK_PATH to point to the actual webpack address used.
diff --git a/apps/website-new/docs/public/words-map.json b/apps/website-new/docs/public/words-map.json
index d3545554228..c19a8471ad2 100644
--- a/apps/website-new/docs/public/words-map.json
+++ b/apps/website-new/docs/public/words-map.json
@@ -156,5 +156,53 @@
}
}
}
+ },
+ "exposeModules":{
+ "id":"exposeModules",
+ "lang":{
+ "zh":{
+ "description":"Module Federation 中 expose 所对应的模块。",
+ "related_meta":{
+ "docs":[],
+ "links":[
+ {
+ "id":"webpack-modules-link",
+ "title":"Webpack modules",
+ "url":"https://webpack.docschina.org/concepts/modules/"
+ }]
+ }
+ },
+ "en":{
+ "description":"The module corresponding to expose in Module Federation.",
+ "related_meta":{
+ "docs":[],
+ "links":[
+ {
+ "id":"webpack-modules-link",
+ "title":"Webpack modules",
+ "url":"https://webpack.js.org/concepts/modules/#root"
+ }]
+ }
+ }
+ }
+ },
+ "FEDERATION_WEBPACK_PATH":{
+ "id":"FEDERATION_WEBPACK_PATH",
+ "lang":{
+ "zh":{
+ "description":"Module Federation 实际使用的 webpack 地址。",
+ "related_meta":{
+ "docs":[],
+ "links":[]
+ }
+ },
+ "en":{
+ "description":"The webpack address actually used by Module Federation.",
+ "related_meta":{
+ "docs":[],
+ "links":[]
+ }
+ }
+ }
}
}
diff --git a/apps/website-new/docs/zh/guide/troubleshooting/_meta.json b/apps/website-new/docs/zh/guide/troubleshooting/_meta.json
index ab616331a3f..9257bd33364 100644
--- a/apps/website-new/docs/zh/guide/troubleshooting/_meta.json
+++ b/apps/website-new/docs/zh/guide/troubleshooting/_meta.json
@@ -6,6 +6,12 @@
"label": "运行时",
"collapsed":true
},
+ {
+ "type": "dir",
+ "name": "build",
+ "label": "构建",
+ "collapsed":true
+ },
{
"type": "dir",
"name": "type",
diff --git a/apps/website-new/docs/zh/guide/troubleshooting/build/BUILD-001.mdx b/apps/website-new/docs/zh/guide/troubleshooting/build/BUILD-001.mdx
new file mode 100644
index 00000000000..16be83baa7e
--- /dev/null
+++ b/apps/website-new/docs/zh/guide/troubleshooting/build/BUILD-001.mdx
@@ -0,0 +1,19 @@
+import ErrorCodeTitle from '@components/ErrorCodeTitle';
+
+
+
+## 原因
+
+未能正常找到 Expose 模块资源。
+
+该问题原因有两个:
+1. `exposes` 设置的 exposeModules 文件路径不正确,指向一个不存在的地址。
+2. 使用了 `Next.js` 或其他内置了 webpack 的框架,MF 使用的 webpack 地址与其不对
+
+## 解决方法
+
+针对原因,有对应的解决方法:
+
+1. 检查 exposes 对应的模块文件路径是否正确,此处注意大小写。
+2. 检查 FEDERATION_WEBPACK_PATH 与框架使用的 webpack 地址是否一致,如果不对,可以查看依赖是否正常安装,或者设置 process.env.FEDERATION_WEBPACK_PATH 指向实际使用的 webpack 地址。
+
diff --git a/packages/enhanced/package.json b/packages/enhanced/package.json
index b685a3b0215..2c79d5b38ba 100644
--- a/packages/enhanced/package.json
+++ b/packages/enhanced/package.json
@@ -88,6 +88,7 @@
"@module-federation/runtime-tools": "workspace:*",
"@module-federation/manifest": "workspace:*",
"@module-federation/managers": "workspace:*",
+ "@module-federation/error-codes": "workspace:*",
"@module-federation/dts-plugin": "workspace:*",
"@module-federation/rspack": "workspace:*",
"@module-federation/bridge-react-webpack-plugin": "workspace:*",
diff --git a/packages/enhanced/src/lib/container/ContainerEntryModule.ts b/packages/enhanced/src/lib/container/ContainerEntryModule.ts
index 3b47697bc8d..58e2461b2c0 100644
--- a/packages/enhanced/src/lib/container/ContainerEntryModule.ts
+++ b/packages/enhanced/src/lib/container/ContainerEntryModule.ts
@@ -5,6 +5,12 @@
'use strict';
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
+import { logger } from '@module-federation/sdk';
+import {
+ getShortErrorMsg,
+ buildDescMap,
+ BUILD_001,
+} from '@module-federation/error-codes';
import type { containerPlugin } from '@module-federation/sdk';
import type { Compilation, Dependency } from 'webpack';
import type {
@@ -229,9 +235,13 @@ class ContainerEntryModule extends Module {
let str;
if (modules.some((m) => !m.module)) {
- str = runtimeTemplate.throwMissingModuleErrorBlock({
- request: modules.map((m) => m.request).join(', '),
- });
+ logger.error(
+ getShortErrorMsg(BUILD_001, buildDescMap, {
+ exposeModules: modules.filter((m) => !m.module),
+ FEDERATION_WEBPACK_PATH: process.env['FEDERATION_WEBPACK_PATH'],
+ }),
+ );
+ process.exit(1);
} else {
str = `return ${runtimeTemplate.blockPromise({
block,
diff --git a/packages/error-codes/src/desc.ts b/packages/error-codes/src/desc.ts
index 3d4dcf14108..c9a09d9bc42 100644
--- a/packages/error-codes/src/desc.ts
+++ b/packages/error-codes/src/desc.ts
@@ -7,6 +7,7 @@ import {
RUNTIME_006,
RUNTIME_007,
TYPE_001,
+ BUILD_001,
} from './error-codes';
export const runtimeDescMap = {
@@ -23,7 +24,12 @@ export const typeDescMap = {
[TYPE_001]: 'Failed to generate type declaration.',
};
+export const buildDescMap = {
+ [BUILD_001]: 'Failed to find expose module.',
+};
+
export const errorDescMap = {
...runtimeDescMap,
...typeDescMap,
+ ...buildDescMap,
};
diff --git a/packages/error-codes/src/error-codes.ts b/packages/error-codes/src/error-codes.ts
index 3901bbf7abf..8f1a5f5d605 100644
--- a/packages/error-codes/src/error-codes.ts
+++ b/packages/error-codes/src/error-codes.ts
@@ -7,3 +7,4 @@ export const RUNTIME_006 = 'RUNTIME-006';
export const RUNTIME_007 = 'RUNTIME-007';
export const TYPE_001 = 'TYPE-001';
+export const BUILD_001 = 'BUILD-001';
diff --git a/packages/error-codes/src/index.ts b/packages/error-codes/src/index.ts
index 9d05ac2fb4e..74d74a9878e 100644
--- a/packages/error-codes/src/index.ts
+++ b/packages/error-codes/src/index.ts
@@ -1,3 +1,8 @@
export * from './error-codes';
export { getShortErrorMsg } from './getShortErrorMsg';
-export { runtimeDescMap, typeDescMap, errorDescMap } from './desc';
+export {
+ runtimeDescMap,
+ typeDescMap,
+ errorDescMap,
+ buildDescMap,
+} from './desc';
diff --git a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
index fd7b5e040c7..074ab98329a 100644
--- a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
+++ b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
@@ -229,7 +229,6 @@ export interface ModuleFederationPluginOptions {
implementation?: string;
manifest?: boolean | PluginManifestOptions;
-
dev?: boolean | PluginDevOptions;
dts?: boolean | PluginDtsOptions;
async?: boolean | AsyncBoundaryOptions;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6bdc83434b3..1a11cf71624 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2179,6 +2179,9 @@ importers:
'@module-federation/dts-plugin':
specifier: workspace:*
version: link:../dts-plugin
+ '@module-federation/error-codes':
+ specifier: workspace:*
+ version: link:../error-codes
'@module-federation/managers':
specifier: workspace:*
version: link:../managers