vite-plugin-federation
vite-plugin-federation copied to clipboard
Remote not able to load, getting [vite] Internal server error: Failed to resolve import "home/Button" from "src/App.jsx". Does the file exist? Plugin: vite:import-analysis
Hello folks, I have 2 repos one as home, another as consumer. From home, i am trying to expose button component which i am not able to import in consumer. Although button is seen in remoteEntry.js file of home repo.
Plz help in how to resolve this issue.
Versions
-@originjs/vite-plugin-federation: "^1.1.6",
- node: v16.15.1
Reproduction
Home
import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import federation from '@originjs/vite-plugin-federation'
// https://vitejs.dev/config/ export default defineConfig({ plugins: [ react(), federation({ filename: 'remoteEntry.js', exposes: { './Button': './src/button.jsx' }, shared: ['react'] }) ], build: { target: 'esnext' } })
consumer
import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import federation from '@originjs/vite-plugin-federation'
// https://vitejs.dev/config/ export default defineConfig({ plugins: [ react(), federation({ name: 'consumer', filename: 'remoteEntry.js', remotes: { 'home': 'http://localhost:3000/dist/assets/remoteEntry.js' }, shared: ['react'] }) ], build: { target: 'esnext' } })
Additional Details
Steps to reproduce
I have attached the code in zip format. vite-react-app.zip
What is Expected?
What is actually happening?
In build mode, it works fine.
Same here !
@ruleeeer seem because of this line: https://github.com/originjs/vite-plugin-federation/blob/3e91b4cff7af4c79b4ac860b236ab5b70e37665f/packages/lib/src/dev/remote-development.ts#L145
the condition need change to builderInfo.isHost && builderInfo.isRemote
.