Cannot find module in vite-plugin-federation

381 Views Asked by At

I have 2 projects, a host app and a remote app. In the remote one I create a Logo component that displays an svg element. I export this component and try to use it in the Header component on the host application, but there I get the error "Cannot find module 'remoteApp/Logo' or its corresponding type declarations". But when I try to import it into App.tsx, there is no error. My vite config in host:

export default defineConfig({
    plugins: [
        react(),
        federation({
            name: "app",
            remotes: {
                remoteApp: "http://localhost:5001/assets/remoteEntry.js",
            },
            shared: ["react", "react-dom"],
        }),
    ],
    
    build: {
        modulePreload: false,
        target: "esnext",
        minify: false,
        cssCodeSplit: false,
    },
});

In remote app:

export default defineConfig({
    plugins: [
        react(),
        federation({
            name: "remote_app",
            filename: "remoteEntry.js",
            exposes: {
                "./Button": "./src/components/Button/Button.tsx",
                "./store": "./src/store.js",
                "./Logo": "./src/components/Logo/Logo.tsx",
            },
            shared: ["react", "react-dom", "jotai"],
        }),
    ],
    build: {
        modulePreload: false,
        target: "esnext",
        minify: false,
        cssCodeSplit: false,
    },
});

I don't know what I did wrong and I'm trying to change the src for the import but it doesn't work

0

There are 0 best solutions below