You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/guide/troubleshooting/other.mdx
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,3 +120,58 @@ export default function MFLinkPlugin(): ModuleFederationRuntimePlugin {
120
120
};
121
121
}
122
122
```
123
+
124
+
## Problem: esm `remoteEntry.js` usage in var `host` environment
125
+
126
+
### Problem
127
+
128
+
There are some cases when your `host` application is written with [ModuleFederationPlugin](https://webpack.js.org/plugins/module-federation-plugin/) and you want to use esm (e.g. `vite`) in your `remote` application.
129
+
And your `host` application doesn't support esm `remote` loading (e.g. your `host` doesn't use `promise new Promise` workaround).
130
+
131
+
In this case you are not able to load `remote` esm application without changing the `host` application.
132
+
133
+
#### Error Message
134
+
:::danger Browser Error Message
135
+
Uncaught SyntaxError: Cannot use import statement outside a module
136
+
:::
137
+
138
+
### Solution
139
+
140
+
If you are not able (or don't want) to rewrite your `host` var environment to support esm `remote` import, you can write a little "var" layer on the `remote`'s side.
141
+
142
+
In you `remote` (`vite`) app create a new workaround file `public/varRemoteEntry.js`:
143
+
144
+
```js
145
+
// public/varRemoteEntry.js
146
+
var remote; // name of remote app
147
+
viteRemote = (function () {
148
+
functiongetScriptUrl() {
149
+
returndocument.currentScript.src
150
+
}
151
+
152
+
constentry=`${getScriptUrl()}/../remoteEntry.js`// path to esm remoteEntry.js
0 commit comments