TypeError: Cannot read properties of null (reading 'useContext')
dawidmarczakcompany opened this issue · 2 comments
dawidmarczakcompany commented
Versions
- vite-plugin-federation: 1.3.5
- vite: 5.2.0
Reproduction
Vite config of the host app
export default defineConfig({
plugins: [
react(),
federation({
name: "my-apps",
remotes: {
dummy: "", //Need to provide some dummy declaration; https://github.com/originjs/vite-plugin-federation/discussions/159#discussioncomment-7633645
},
shared: ["react", "react-dom"],
}),
],
build: {
target: "esnext",
},
});
Vite config of the remote app
export default defineConfig({
plugins: [
react(),
federation({
name: 'mf,
filename: 'mf.js',
exposes: {
'./App': './src/components/App/App.tsx',
},
shared: ['react', 'react-dom'],
}),
],
build: {
target: 'esnext',
},
});
What is Expected?
Remote loads correctly
What is actually happening?
I got error - TypeError: Cannot read properties of null (reading 'useContext')
Anyone have solution for this?
LechLee commented
Might wan to try
export default defineConfig({
plugins: [
react(),
federation({
name: "my-apps",
remotes: {
dummy: "", //Need to provide some dummy declaration; https://github.com/originjs/vite-plugin-federation/discussions/159#discussioncomment-7633645
},
shared: {
react: { singleton: true, requiredVersion: '^18.2.0' },
'react-dom': { singleton: true, requiredVersion: '^18.2.0' },
},
}),
],
build: {
target: "esnext",
},
});
dawidmarczakcompany commented
I found the solution - in the "shared" object I had to add also "react-redux" as I had this library used in host and microfront.
Errors from module federation are unclear in this case, and they didn't say anything about Redux.