Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vite] Uncaught ReferenceError: useForkRef_default is not defined #26078

Closed
Roy-Kid opened this issue May 1, 2021 · 8 comments
Closed

[vite] Uncaught ReferenceError: useForkRef_default is not defined #26078

Roy-Kid opened this issue May 1, 2021 · 8 comments
Labels
component: accordion This is the name of the generic UI component, not the React module!

Comments

@Roy-Kid
Copy link

Roy-Kid commented May 1, 2021

  • [ x] The issue is present in the latest release.
  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

I want to add an accordion. I try simpleDrawer in the example, but one error raises:
image
My code is:
image
and the component SimpleAccordion is directly copied from example: https://material-ui.com/zh/components/accordion/

I'm new to the frontend so I don't know what's going wrong.
Thanks in advance!

Expected Behavior 🤔

PS: I want to use the accordion in the Drawer, to implement the effect like this:
image

is it possible?

@Roy-Kid Roy-Kid added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 1, 2021
@oliviertassinari oliviertassinari added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 1, 2021
@oliviertassinari
Copy link
Member

@Roy-Kid Please provide a minimal reproduction test case with the latest version. This would help a lot 👷 .
A live example would be perfect. This codesandbox.io template may be a good starting point. Thank you!

@Roy-Kid
Copy link
Author

Roy-Kid commented May 1, 2021

@oliviertassinari Thanks for your help!

I use vite(with react template) to generate the project and use its own dev server.

Here is the main.jsx code:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import TabBar from './tabBar';
import Visualization from "./visualization";
import SimpleAccordion from './taskPanel';

ReactDOM.render(
  <React.StrictMode>

    <SimpleAccordion />
    
  </React.StrictMode>,
  document.getElementById('root')
)

and the <SimpleAccordion/> is directly copied from official code:

const useStyles = makeStyles((theme) => ({
  root: {
    width: '100%',
  },
  heading: {
    fontSize: theme.typography.pxToRem(15),
    fontWeight: theme.typography.fontWeightRegular,
  },
}));

export default function SimpleAccordion() {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <Accordion>
        <AccordionSummary
          expandIcon={<ExpandMoreIcon />}
          aria-controls="panel1a-content"
          id="panel1a-header"
        >
          <Typography className={classes.heading}>Accordion 1</Typography>
        </AccordionSummary>
        <AccordionDetails>
          <Typography>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse malesuada lacus ex,
            sit amet blandit leo lobortis eget.
          </Typography>
        </AccordionDetails>
      </Accordion>
      <Accordion>
        <AccordionSummary
          expandIcon={<ExpandMoreIcon />}
          aria-controls="panel2a-content"
          id="panel2a-header"
        >
          <Typography className={classes.heading}>Accordion 2</Typography>
        </AccordionSummary>
        <AccordionDetails>
          <Typography>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse malesuada lacus ex,
            sit amet blandit leo lobortis eget.
          </Typography>
        </AccordionDetails>
      </Accordion>
      <Accordion disabled>
        <AccordionSummary
          expandIcon={<ExpandMoreIcon />}
          aria-controls="panel3a-content"
          id="panel3a-header"
        >
          <Typography className={classes.heading}>Disabled Accordion</Typography>
        </AccordionSummary>
      </Accordion>
    </div>
  );
}

and then run the npm run dev, in the chrome debug panel the error raise.
This the repo that the error raise. I am so sorry that I have no experiment to frontend and no friend to ask. Thanks again for your help !!!
https://github.com/Roy-Kid/molvis/tree/vitedev

@oliviertassinari
Copy link
Member

It looks like an issue with vite. Did you try using Material-UI v5 as well?

@Roy-Kid
Copy link
Author

Roy-Kid commented May 1, 2021

I'm going to a meeting. After I'll try create-react-app and v5 when I get back. Thanks for your kindly help!

@Roy-Kid
Copy link
Author

Roy-Kid commented May 7, 2021

First, I port v4 to v5 but not fix the problem. Then I use code sandbox it works. I pretty sure that is an issue with vite.

image

Can I use create-react-app to replace with vite?

@oliviertassinari
Copy link
Member

@Roy-Kid You can switch, but I think that it would be better for us to make sure it works with Vite! It's popular: https://bestofjs.org/projects/vite.

@Roy-Kid
Copy link
Author

Roy-Kid commented May 8, 2021

Hi, I am so glad to help the community. If you need anything, please say so. I need a lot of learning to contribute to the community

@oliviertassinari oliviertassinari changed the title useForkRef is not defined when using accordion [vite] Uncaught ReferenceError: useForkRef_default is not defined May 8, 2021
@oliviertassinari oliviertassinari removed the status: waiting for author Issue with insufficient information label May 8, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented May 8, 2021

@Roy-Kid Ok, I had a look. I could reproduce the issue with the latest versions (v5). It's an issue with the icons package. This fixes the issue: #21377 (comment).

If you want to add a new /examples in our repo with vite, feel free too.

@zannager zannager added the component: accordion This is the name of the generic UI component, not the React module! label Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: accordion This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

3 participants