Giter Club home page Giter Club logo

Comments (11)

ruleeeer avatar ruleeeer commented on May 29, 2024 2

I will fix this, but it will take some time and if it's urgent I suggest you use webpack

from vite-plugin-federation.

sanyuan0704 avatar sanyuan0704 commented on May 29, 2024 1

I will fix this, but it will take some time and I suggest you use webpack

Have you fixed it?I meet the same problem.

from vite-plugin-federation.

ruleeeer avatar ruleeeer commented on May 29, 2024

I assume you have other component libraries that use react/react-dom, please add them to shared as well, otherwise it may result in multiple different react/react-dom in the runtime environment

from vite-plugin-federation.

lolocoo avatar lolocoo commented on May 29, 2024

I assume you have other component libraries that use react/react-dom, please add them to shared as well, otherwise it may result in multiple different react/react-dom in the runtime environment

I add all of them

remote component

import React ,{useState} from "react";

export default ({caption = "Home Button"}) => {
  const [count, setCount] = useState(0)
  return (<button onClick={() => setCount(count+1) } className='remote-btn'>{caption}{count}</button>)
};
  shared: {
      react: { singleton: true },
      'react-dom': {
        singleton: true,
      },
      antd: {
        singleton: true,
      },
    },

warning

Uncaught TypeError: Cannot read properties of undefined (reading 'exports')
    at __federation_shared_antd.js:1:438

if remove the hook call it will be ok.

reference webpack remote component with hook call it run well too

from vite-plugin-federation.

ruleeeer avatar ruleeeer commented on May 29, 2024

This problem seems strange, can you provide me with a link to a repository or sandbox where I can reproduce the problem?

from vite-plugin-federation.

lolocoo avatar lolocoo commented on May 29, 2024

Here is git respository https://github.com/lolocoo/vite-federation-issue-reproduce.git

export default ({caption = "Home Button"}) => {
  const [count, setCount] = useState(0)
  return (<button onClick={() => setCount(count+1) } className='remote-btn'>{caption}{count}</button>)
};

cause error TypeError: Cannot read properties of undefined (reading 'exports')
const [count, setCount] = react.exports.useState(0);

use React.useState fix the problem.

export default ({caption = "Home Button"}) => {
  const [count, setCount] = React.useState(0)
  return (<button onClick={() => setCount(count+1) } className='remote-btn'>{caption}{count}</button>)
};

when I refrence a component from ui library like ant.design

import React, { useState } from "react";
import { Button  } from 'antd'

export default ({caption = "Home Button"}) => {
  const [count, setCount] = React.useState(0)
  return (<Button onClick={() => setCount(count+1) } className='remote-btn'>{caption}{' '}{count}</Button>)
};

cause the error Cannot read properties of undefined (reading 'exports'). react.exports.Component

from vite-plugin-federation.

ruleeeer avatar ruleeeer commented on May 29, 2024

I found some problems after checking out the repository,when I use dev mode, the console also reports an error
I tried to use build & serve to start the host side and found that it works, I get the following result

image

If this result is normal, the reason should be that there are some problems with the plugin's support for react in dev mode

from vite-plugin-federation.

lolocoo avatar lolocoo commented on May 29, 2024

I found some problems after checking out the repository,when I use dev mode, the console also reports an error I tried to use build & serve to start the host side and found that it works, I get the following result

image

If this result is normal, the reason should be that there are some problems with the plugin's support for react in dev mode

Thank you for your help. Will you solve this problem? I will use it in my project if not will migrate vite to webpack. It's so painfull.

from vite-plugin-federation.

UrielJavier avatar UrielJavier commented on May 29, 2024

i have the same problem :/

from vite-plugin-federation.

chancmg avatar chancmg commented on May 29, 2024

We are facing the same issue.. Can we re-open the issue?

from vite-plugin-federation.

yuvalbne avatar yuvalbne commented on May 29, 2024

@ruleeeer @sanyuan0704
Someone have an idea about this issue???

from vite-plugin-federation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.