Skip to content

Commit 8d34aa8

Browse files
authored
chore: unify error code (#3156)
1 parent 024df60 commit 8d34aa8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1709
-1395
lines changed

apps/website-new/docs/en/guide/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
"type": "dir",
1414
"name": "framework",
1515
"label": "Frameworks"
16+
},
17+
{
18+
"type":"dir",
19+
"name":"troubleshooting",
20+
"label":"Troubleshooting"
1621
}
1722
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["runtime", "rspack", "webpack", "rsbuild", "vite", "chrome-devtool", "type-prompt", "error-catalog"]
1+
["runtime", "rspack", "webpack", "rsbuild", "vite", "chrome-devtool", "type-prompt"]

apps/website-new/docs/en/guide/basic/error-catalog.mdx

Lines changed: 0 additions & 195 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
"overview",
3+
{
4+
"type": "dir",
5+
"name": "runtime",
6+
"label": "Runtime",
7+
"collapsed":true
8+
},
9+
{
10+
"type": "dir",
11+
"name": "type",
12+
"label": "Type",
13+
"collapsed":true
14+
},
15+
"other"
16+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Other
2+
3+
This section is a collection of common issues related to the implementation of `Module Federation` in general(not specific error code).
4+
The main goal is to provide additional context and solution paths for beginners not familiar with the fundamental ways of how `Module Federation` is working at its core.
5+
6+
## Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
7+
#### Error Message
8+
:::danger Browser Error Message
9+
Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
10+
11+
You might have mismatching versions of React and the renderer (such as React DOM)
12+
13+
You might be breaking the Rules of Hooks
14+
15+
You might have more than one copy of React in the same app
16+
:::
17+
18+
:::danger Browser Error Message
19+
Uncaught TypeError: Cannot read properties on null (reading `useState`)
20+
:::
21+
22+
#### Solution
23+
24+
This error is a React multi-instance problem, which usually occurs when react does not reuse the same instance.
25+
This problem can be avoided by setting `shared` and setting `singleton: true` singleton mode.
26+
27+
```ts title="modern.config.js"
28+
{
29+
...
30+
new ModuleFederationPlugin({
31+
...,
32+
// Default basic configuration
33+
// shared: [
34+
// 'react',
35+
// 'react-dom',
36+
// 'my-custom-module'
37+
// ]
38+
39+
// Configuration with more specificity
40+
shared: {
41+
react: { singleton: true, },
42+
'react-dom': { singleton: true, },
43+
'my-custom-module': { singleton: true, },
44+
...
45+
},
46+
})
47+
])
48+
}
49+
```
50+
51+
## Unable to compile federated types, Error: compile TS failed
52+
53+
#### Error Message
54+
:::danger Browser Error Message
55+
Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project file-path.json'.
56+
:::
57+
58+
:::danger Browser Error Message
59+
Error: ENOENT: no such file or directory, open 'project-path/rspack_hmr/application-name/dist/@mf-types.zip'
60+
:::
61+
62+
#### Solution
63+
64+
1. Execute `npx tsc --project file-path.json` according to the error message to solve all type problems encountered.
65+
2. Check your `ModuleFederationPlugin` config field `exposes`:
66+
67+
```ts title="[modern|rspack|rsbuild|webpack].config.[js,ts]"
68+
new ModuleFederationPlugin({
69+
...
70+
// Make sure both key and value start with "./"
71+
exposes: { './Foo': './src/<path-to-file>/Foo.tsx' },
72+
...
73+
})
74+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Overview
2+
3+
Module Federation currently provides **Build Tools**, **Runtime API**, **Type Hints** and **Debugging Tools**. In order to locate the corresponding problems faster, we classify error messages. Divide them into the following categories:
4+
5+
* [Runtime](./runtime/RUNTIME-001)
6+
* [Type](./type/TYPE-001)
7+
* Build
8+
* Debugging tools
9+
10+
And for the information thrown internally, specific error codes will be given. The error code consists of the error type and ID (such as **RUNTIME-001**). You can find the specified page based on the error code to learn about the cause and solution of the error.
11+
12+
For common problems when using third-party packages, we have placed them in the [Other](./other) chapter, such as high-frequency React multi-instance problems, etc.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ErrorCodeTitle from '@components/ErrorCodeTitle';
2+
import Table from '@components/Table'
3+
4+
<ErrorCodeTitle code='RUNTIME-001'/>
5+
6+
7+
## Reasons
8+
9+
When the producer entry file is loaded normally, the producer will be registered in the global object (globalThis/window), which can be accessed through window[remoteEntryKey].
10+
11+
However, during this loading process, registered producers are inaccessible. There are three possible causes for this error:
12+
13+
1. The remoteEntryUrl is not right.
14+
2. The remoteEntry file does not mount the container correctly.
15+
3. Network problem, the resource cannot be accessed.
16+
17+
## Solutions
18+
19+
There are corresponding solutions for the reasons:
20+
21+
1. Check whether the remoteEntryUrl is correct.
22+
- If using manifest, check the publicPath and remoteEntry.name fields in the manifest
23+
2. If the project builder is rspack, check whether [runtimeChunk](https://rspack.dev/config/optimization#optimizationruntimechunk) is set in the final build configuration. If so, delete this configuration.
24+
3. Check if the resource is externally accessible.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import ErrorCodeTitle from '@components/ErrorCodeTitle';
2+
import Table from '@components/Table'
3+
4+
<ErrorCodeTitle code='RUNTIME-002'/>
5+
6+
7+
## Reasons
8+
9+
Can not get remote container `init` function.
10+
11+
The remote container should provide an object which value is `{ get, init }`. However, the `init` is `undefined` during this load.
12+
13+
## Solutions
14+
15+
Check in the following order:
16+
17+
1. Before loading the producer, enter window[remoteEntryKey] in `terminal` to check whether this object is occupied. If so, you need to rename the producer [name](../../../configure/name#name)
18+
2. If the project builder is rspack, check whether [runtimeChunk](https://rspack.dev/config/optimization#optimizationruntimechunk) is set in the final build configuration. If so, delete this configuration.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import ErrorCodeTitle from '@components/ErrorCodeTitle';
2+
3+
<ErrorCodeTitle code='RUNTIME-003'/>
4+
5+
## Reasons
6+
7+
Failed to load the manifest, the manifest url may be wrong
8+
9+
## Solutions
10+
11+
1. Check whether manifestUrl can be accessed normally alone
12+
2. Check manifestUrl for cross-domain issues
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import ErrorCodeTitle from '@components/ErrorCodeTitle';
2+
3+
<ErrorCodeTitle code='RUNTIME-004'/>
4+
5+
## Reasons
6+
7+
The matching remote module cannot be found. This error may be caused by the following x reasons:
8+
1. The corresponding producer information is not registered with the consumer.
9+
2. requestId uses the wrong alias or name
10+
3. There is a `beforeRequest` hook registered and the correct data is not returned
11+
12+
## Solutions
13+
14+
There are corresponding solutions for the reasons:
15+
16+
1. Check whether the producer information for this request is registered with the consumer
17+
2. Check whether the registered producer information (name/alias) is consistent with requestId
18+
3. Check whether the `beforeRequest` hook is additionally registered in the project, and modify the runtime plug-in of the parameters

0 commit comments

Comments
 (0)