vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

无法在remote提供的代码中使用 hooks

Open shinehs opened this issue 3 years ago • 0 comments

Versions

  • vite-plugin-federation: v1.1.9
  • vite: v3.0.3
  • react: 18.2.0

Reproduction

如果在remote提供的模块中,使用例如useEffect这样的hook,在host项目中使用该模块提供的组件的时候,直接会一个V.current.useEffect未定义的错误。

Additional Details

Steps to reproduce

这样提供组件没问题

import React, {useEffect} from "react";

const App = () => {
  return (
    <div
      style={{
        margin: "10px",
        padding: "10px",
        textAlign: "center",
        backgroundColor: "cyan",
      }}
    >
      <h1>组件来自 App 2 中的代码</h1>
    </div>
  );
};

export default App;

这样就会报错

import React, {useEffect} from "react";

const App = () => {
  useEffect(()=>{
    console.log(1);
  },[])
  return (
    <div
      style={{
        margin: "10px",
        padding: "10px",
        textAlign: "center",
        backgroundColor: "cyan",
      }}
    >
      <h1>组件来自 App 2 中的代码</h1>
    </div>
  );
};

export default App;

我的配置:

{
 plugins: [
 react(),
 federation({
        name: 'demo',
        filename: 'entry.js',
        library: { type: 'module' },
        exposes: {
          './Demo': './src/components/index.tsx'
        },
        shared: ['react']
      })
 ]
}

What is Expected?

希望得到回复

What is actually happening?

image 原因是在打包的代码块中: image

shinehs avatar Sep 21 '22 07:09 shinehs