FAQ
1. Error Fetching Sub-app Resources
Error message: Access to fetch at *** from origin *** has been blocked by CORS policy: No 'Access-Control-Allow-Origin'
Cause: The sub-app server does not allow cross-origin requests, or the resource request requires cookies that are not being sent.
Solution:
If the issue is missing CORS headers, see Prerequisites.
If the issue is missing cookies (commonly seen when requests return
302redirects to a login page), pass a custom fetch withcredentials: "include"so cookies are attached.
Warning
When credentials is set to "include", the server cannot return Access-Control-Allow-Origin: * (see MDN: Credentialed requests and wildcards). Echo the request origin explicitly on the server instead:
ctx.set("Access-Control-Allow-Origin", ctx.headers.origin);
2. Third-Party Package Imported but Throws Error at Runtime
Cause: Normally, top-level scripts execute in the global scope so variables declared with var xxx attach directly to window. However, Wujie wraps sub-app scripts in a closure in order to proxy location. As a result, var xxx stays scoped inside that closure rather than attaching to window, and asynchronous chunks executed in another closure cannot read it.
Solution:
Explicitly attach the global variable to
window(e.g.,window.xxx = ...), or configure Webpack'soutput.libraryTargetto"window".If you cannot modify the third-party package, use the js-loader plugin to rewrite
xxx=towindow.xxx=at runtime.
3. Sub-app Custom Fonts Do Not Take Effect
Cause: @font-face rules declared inside Shadow DOM are not loaded by browsers (see mdn/interactive-examples#887).
Handled by Wujie: Wujie automatically hoists sub-app @font-face rules outside the Shadow DOM. Just ensure custom font family names do not collide between the main app and sub-apps to avoid overrides.
4. Popover / Dropdown Positioning Is Incorrect
Cause: Libraries such as element-plus use popper.js v2, which walks ancestor elements up to window.visualViewport to compute offsets. Because a sub-app's DOM is mounted inside shadowRoot, scroll offsets relative to window.visualViewport are miscalculated.
Solution: Set position: relative on the sub-app's body.
5. e.target Becomes wujie-app in Async Event Handlers
Cause: This is standard browser Shadow DOM event retargeting behavior (see Stack Overflow).
Solution: Resolve the real target inside asynchronous handlers using: (e.target.shadowRoot && e.composed) ? (e.composedPath()[0] || e.target) : e.target
6. Relative URLs Inside CSS Resolve Against the Main App Domain
Handled by Wujie: Wujie automatically rewrites relative URLs in <style> tags and external CSS files into absolute URLs based on the sub-app origin.
7. Error Loading Remote Modules with Module Federation
Cause: Same as FAQ #2 — closure-wrapped script execution prevents global variables declared in one script from being visible in another.
Solution: Set library.type to "window" in ModuleFederationPlugin:
library: { type: "window", name: "same-as-plugin-name" }
8. Sub-app iframe Loads and Executes Main App Assets During Initialization
Cause: See Tencent/wujie#54.
Solution:
- Serve an empty endpoint on the main app's origin (for example,
https://host/emptyreturning an empty 200 response) and pass attrs as{ src: "https://host/empty" }so the sandbox iframe loads that empty URL. - Alternatively, place
<script>if (window.parent !== window) { window.stop(); }</script>as the first element inside the main app's<head>to prevent main app scripts from running inside the sandbox iframe.
9. Sub-app window Is a Proxy — How to Get the Real window Object
Cause: See Tencent/wujie#63 for why Wujie proxies window.
Solution:
- Use
window.__WUJIE_RAW_WINDOW__to access the native unproxiedwindowobject. See Global Variables.
10. DOMException: Blocked a frame with origin from accessing a cross-origin frame
Possible Causes: The sub-app's iframe sandbox has been navigated away or replaced. Three common causes:
- The sub-app runs inside an iframe whose
srcis the main app'shost, and that URL triggers a redirect (such as a302to a cross-origin SSO login page), replacing the sandbox. - The sub-app is built with
Viteand assigns towindow.location.href, navigating the iframe away. - A script configured in jsIgnores assigns to
window.location.href.
Solution:
- Provide a non-redirecting empty path on the main app's origin (such as
https://host/empty) and set attrs to{ src: "https://host/empty" }. - In
Vitesub-apps, usewindow.$wujie.locationfor alllocationoperations. - In scripts listed under
jsIgnores, usewindow.$wujie.locationfor alllocationoperations.
11. Sub-app Relative Asset URLs Request the Main App Domain
Cause: In standard (non-degrade) mode, the sub-app's DOM is mounted inside the main app document's shadowRoot, so relative URLs on elements like images and videos resolve against the main app's URL instead of the sub-app's.
Handled by Wujie: Relative URLs on the following element attributes are automatically resolved to the sub-app's origin — whether written in HTML templates or set dynamically via setAttribute, property assignment (e.g., img.src = ...), or innerHTML (including v-html):
| Element | Attribute |
|---|---|
img, source | src, srcset |
video | src, poster |
audio, track, iframe, embed | src |
object | data |
a, link | href |
script | src |
SVG image | href, xlink:href |
Fragment-only URLs starting with # are left untouched. Versions 2.1.1 and earlier only covered src / href on img, a, source, link, script, video, and audio and did not rewrite innerHTML; upgrading covers the full table above.
Still requires manual handling: url() inside inline style attributes (for <style> blocks and external CSS files, see FAQ #6), as well as HTML inserted via insertAdjacentHTML, outerHTML, or similar APIs.
Recommended Best Practice: Configure your build so asset URLs do not depend on document base-URL resolution, using either approach below:
- Use absolute asset URLs with the sub-app origin. For Webpack sub-apps, import
./configat the very top of yourmainentry file with the snippet below; for Vite sub-apps, setbaseto the full sub-app origin URL:
if (window.__POWERED_BY_WUJIE__) {
// eslint-disable-next-line
window.__webpack_public_path__ = window.__WUJIE_PUBLIC_PATH__;
}
- Configure a same-origin reverse proxy on the main app to forward sub-app asset paths to the sub-app server (ensure asset path prefixes do not collide with the main app).
12. Vite 4 Sub-app Loses Styles When Switching
See Tencent/wujie#434 for the root cause and workaround.
