vite-plugin-federation icon indicating copy to clipboard operation
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

Open shrinkhala15 opened this issue 2 years ago • 1 comments

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?

shrinkhala15 avatar Jun 24 '22 13:06 shrinkhala15

In build mode, it works fine.

flyfishzy avatar Jul 02 '22 09:07 flyfishzy

Same here !

devbucket avatar Oct 20 '22 10:10 devbucket

@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.

we125182 avatar Dec 16 '22 10:12 we125182