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

Box modules is broken #43242

Open
howtorespawn opened this issue Aug 9, 2024 · 7 comments
Open

Box modules is broken #43242

howtorespawn opened this issue Aug 9, 2024 · 7 comments
Assignees
Labels
component: Box The React component. status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@howtorespawn
Copy link

howtorespawn commented Aug 9, 2024

Steps to reproduce

Link to live example: (required)

Steps:

  1. Just use mui + Vite
  2. On Vite Use react, javascrip + SWC
  3. Install MUI
  4. Use Drawer (or anything else that has box modules in it)
  5. make two components. Use box of one component on second one.
    Like this
    src > components
  6. box1.jsx
  7. box2.jsx

import box 1 into box 2 and refresh the page manually (reenter url)

it gives off error in console that

Uncaught TypeError: undefined is not a function
<anonymous> Box.js:9

this line is giving problem
```const defaultTheme = createTheme();``
Check with both FireFox and Chromium

Current behavior

Box modules shows error in this line:
const defaultTheme = createTheme();
invalid function

Expected behavior

It should run

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: box mui

@howtorespawn howtorespawn added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 9, 2024
@mnajdova
Copy link
Member

It doesn't look like this bug report has enough info for one of us to reproduce it.
Please provide a CodeSandbox (https://material-ui.com/r/issue-template-latest), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem.
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve

@mnajdova mnajdova 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 Aug 12, 2024
Copy link

Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.

@slittlec
Copy link

I also get this error with Box and Vite:

const defaultTheme = createTheme();

Box.js:9
Uncaught TypeError: createTheme_default is not a function
at Box.js:9:22

@imakecodes
Copy link

I'm seeing the same error

@howtorespawn
Copy link
Author

howtorespawn commented Sep 16, 2024

@slittlec @imakecodes if possible then create a new issue or share code here with help of https://codesandbox.io/ or just paste it here and ping mnajdova to reopen this issue post.
I lost my code so cant share it nor reproduce since my laptop is kinda broken to write the code correctly and with pace

for author

Edit:
I tried recreating it, not sure why but it seems like issue isnt with drawer + box but just single box modules

import { useState } from 'react'
import './App.css'
import * as React from 'react';
import Box from '@mui/material/Box';
import { ThemeProvider } from '@mui/material/styles';

function App() {
  return (
    <>
    <ThemeProvider
      theme={{
        palette: {
          primary: {
            main: '#007FFF',
            dark: '#0066CC',
          },
        },
      }}
    >
      <Box
        sx={{
          width: 100,
          height: 100,
          borderRadius: 1,
          bgcolor: 'primary.main',
          '&:hover': {
            bgcolor: 'primary.dark',
          },
        }}
      />
    </ThemeProvider>
    </>
  )
}

export default App

Paste this into your app.jsx (vite + react with js)
image
the error is generated again due to https://mui.com/material-ui/react-box/#customization this code alone
Not sure why since i deleted

EDIT 2: upon further inspection the problem is with

import { Box } from '@mui/material'              //works
import Box from '@mui/material/Box';         // haha skill issue, fix theme or smt ~ prob the code

Found this right before starting to beat my head on wall

Solution for temporary

just replace the
import Box from '@mui/material/Box'
with
import { Box } from '@mui/material'
at top of your program for temporary solution. let developers do the rest of fixing for permanent solution

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Sep 16, 2024
@github-actions github-actions bot reopened this Sep 16, 2024
@zannager zannager added the component: Box The React component. label Sep 17, 2024
@imakecodes
Copy link

Hey folks, I solved this issue modifying the imports from import Box from '@mui/material/Box'; to `import { Box } from '@mui/material';

I'm using vite to serve, what are other infos important that could help to understand what is happening?

@mnajdova mnajdova assigned brijeshb42 and Janpot and unassigned mnajdova Oct 22, 2024
@Janpot
Copy link
Member

Janpot commented Oct 23, 2024

same as #44055 (comment) I'd try if the new package structure of next MUI major fixes this issue.

if you feel like experimenting, there may also be a workaround to alias the imports to the esm folder such as in #35233 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Box The React component. status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

7 participants