Я пытаюсь модуль федерации с помощью Vite-React. Я сделал все конфигурации в файле vite.config.js как на хосте, так и в удаленном. Но когда я получаю доступ к импортированным файлам удаленного дистанционного управления на хосте, он показывает пустой экран
Я пытаюсь настроить федерацию модулей с помощью VITE с использованием @Originjs/Vite-Plugin-Federation. У меня есть удаленное приложение, разоблачающее компоненты и хост -приложение, импортирующее их. Однако, когда я пытаюсь получить доступ к http: // localhost: 5173/arsets/remoteentry.js, он возвращает HTML -страницу вместо JavaScript.
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import federation from '@originjs/vite-plugin-federation';
export default defineConfig({
plugins: [
react(),
federation({
name: 'remote_app',
filename: 'remoteEntry.js',
exposes: {
'./Button': './src/button.jsx',
'./Header': './src/components/Header.jsx'
},
shared: ["react", "react-dom", "jotai"],
})
],
build: {
modulePreload: false,
target: 'esnext',
minify: false,
cssCodeSplit: false
},
});
< /code>
Это удаленная конфигурация. Попытка обмена кнопкой и заголовком < /p>
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import federation from '@originjs/vite-plugin-federation';
export default defineConfig({
plugins: [
react(),
federation({
name: 'host_app',
remotes: {
remote_app: 'http://localhost:5173/assets/remoteEntry.js'
},
shared: ["react", "react-dom"]
})
],
build: {
modulePreload: false,
target: 'esnext',
minify: false,
cssCodeSplit: false
}
});
< /code>
Это конфигурация хоста < /p>
Компоненты загрузки в приложении хоста < /p>
const RemoteButton = React.lazy(() => import('remote_app/Button'))
const Header = React.lazy(() => import('remote_app/Header'))
< /code>
< /code>
versions:
"@vitejs/plugin-react-swc": "^3.5.0",
"@originjs/vite-plugin-federation": "^1.3.9",
"react-router-dom": "^7.2.0",
When i navigated to /button route or /header route it is a blank screen.
For debugging i tried to import with promise function in useEffect of App.jsx
useEffect(() => {
import("remote_app/Button")
.then((module) => {
console.log("RemoteButton loaded:", module);
})
.catch((error) => {
console.error("Failed to load RemoteButton:", error);
});
}, []);
< /code>
Error i the browser console:
Uncaught TypeError: Failed to fetch dynamically imported module: http://localhost:5173/assets/remoteEntry.js
in the browser console following error is shown
Network tab response for http://localhost:5173/assets/remoteEntry.js:
Status: 200
Response Body: Instead of JS, it returns the default Vite HTML page
import { injectIntoGlobalHook } from "/@react-refresh";
injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
Vite + React
< /code>
What I Have Tried:
Checked the remoteEntry.js URL: It loads an HTML page instead of a JS module.
Manually importing in useEffect:
useEffect(() => {
import("remote_app/Button")
.then((module) => {
console.log("RemoteButton loaded:", module);
})
.catch((error) => {
console.error("Failed to load RemoteButton:", error);
});
}, []);
< /code>
Expected Outcome:
http://localhost:5173/assets/remoteEntry.js should return the federated module, not an HTML page.
Remote components should load successfully in the host app.
Why is remoteEntry.js not being generated properly, and how do I fix this?
Both host and remote vite+react applications.
I tried in many ways but i can't understand what is the mistake.
Подробнее здесь: https://stackoverflow.com/questions/794 ... tead-of-js
Федерация модулей Vite: remoteEntry.js возвращает html вместо JS ⇐ Javascript
Форум по Javascript
-
Anonymous
1740368264
Anonymous
Я пытаюсь модуль федерации с помощью Vite-React. Я сделал все конфигурации в файле vite.config.js как на хосте, так и в удаленном. Но когда я получаю доступ к импортированным файлам удаленного дистанционного управления на хосте, он показывает пустой экран
Я пытаюсь настроить федерацию модулей с помощью VITE с использованием @Originjs/Vite-Plugin-Federation. У меня есть удаленное приложение, разоблачающее компоненты и хост -приложение, импортирующее их. Однако, когда я пытаюсь получить доступ к http: // localhost: 5173/arsets/remoteentry.js, он возвращает HTML -страницу вместо JavaScript.
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import federation from '@originjs/vite-plugin-federation';
export default defineConfig({
plugins: [
react(),
federation({
name: 'remote_app',
filename: 'remoteEntry.js',
exposes: {
'./Button': './src/button.jsx',
'./Header': './src/components/Header.jsx'
},
shared: ["react", "react-dom", "jotai"],
})
],
build: {
modulePreload: false,
target: 'esnext',
minify: false,
cssCodeSplit: false
},
});
< /code>
Это удаленная конфигурация. Попытка обмена кнопкой и заголовком < /p>
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import federation from '@originjs/vite-plugin-federation';
export default defineConfig({
plugins: [
react(),
federation({
name: 'host_app',
remotes: {
remote_app: 'http://localhost:5173/assets/remoteEntry.js'
},
shared: ["react", "react-dom"]
})
],
build: {
modulePreload: false,
target: 'esnext',
minify: false,
cssCodeSplit: false
}
});
< /code>
Это конфигурация хоста < /p>
Компоненты загрузки в приложении хоста < /p>
const RemoteButton = React.lazy(() => import('remote_app/Button'))
const Header = React.lazy(() => import('remote_app/Header'))
< /code>
< /code>
versions:
"@vitejs/plugin-react-swc": "^3.5.0",
"@originjs/vite-plugin-federation": "^1.3.9",
"react-router-dom": "^7.2.0",
When i navigated to /button route or /header route it is a blank screen.
For debugging i tried to import with promise function in useEffect of App.jsx
useEffect(() => {
import("remote_app/Button")
.then((module) => {
console.log("RemoteButton loaded:", module);
})
.catch((error) => {
console.error("Failed to load RemoteButton:", error);
});
}, []);
< /code>
Error i the browser console:
Uncaught TypeError: Failed to fetch dynamically imported module: http://localhost:5173/assets/remoteEntry.js
in the browser console following error is shown
Network tab response for http://localhost:5173/assets/remoteEntry.js:
Status: 200
Response Body: Instead of JS, it returns the default Vite HTML page
import { injectIntoGlobalHook } from "/@react-refresh";
injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
Vite + React
< /code>
What I Have Tried:
Checked the remoteEntry.js URL: It loads an HTML page instead of a JS module.
Manually importing in useEffect:
useEffect(() => {
import("remote_app/Button")
.then((module) => {
console.log("RemoteButton loaded:", module);
})
.catch((error) => {
console.error("Failed to load RemoteButton:", error);
});
}, []);
< /code>
Expected Outcome:
http://localhost:5173/assets/remoteEntry.js should return the federated module, not an HTML page.
Remote components should load successfully in the host app.
Why is remoteEntry.js not being generated properly, and how do I fix this?
Both host and remote vite+react applications.
I tried in many ways but i can't understand what is the mistake.
Подробнее здесь: [url]https://stackoverflow.com/questions/79462408/vite-module-federation-remoteentry-js-returns-html-instead-of-js[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия