Giter Site home page Giter Site logo

Comments (14)

michelengelen avatar michelengelen commented on July 22, 2024 2

For me it does not start with the ThemeProvider bein the source of error:

❯ npm run start

> start
> remix-serve ./build/server/index.js

file:///Users/michel/_work/remix-vite-mui-issue/build/server/index.js?t=1709029858736.2107:9
import { ThemeProvider } from "@mui/material/styles/index.js";
         ^^^^^^^^^^^^^
SyntaxError: Named export 'ThemeProvider' not found. The requested module '@mui/material/styles/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@mui/material/styles/index.js';
const { ThemeProvider } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at ModuleJob.run (node:internal/modules/esm/module_job:190:5)

@LukasTy could you try as well?

from mui-x.

raskyer avatar raskyer commented on July 22, 2024 1

But this seems to work :
https://stackoverflow.com/questions/78017516/vite-ssr-build-fails-with-mui-icons-and-date-time-picker

import { AdapterDayjs} from "@mui/x-date-pickers/node/AdapterDayjs";

from mui-x.

raskyer avatar raskyer commented on July 22, 2024 1

Also change your import of ThemeProvider to : import { ThemeProvider } from '@mui/material';

And your import of blue should become : import { colors } from '@mui/material';
colors.blue

from mui-x.

tcov189 avatar tcov189 commented on July 22, 2024 1

You need to remove the import commonjs from "vite-plugin-commonjs" from vite config

Also change your import of ThemeProvider to : import { ThemeProvider } from '@mui/material';

And your import of blue should become : import { colors } from '@mui/material'; colors.blue

@raskyer This did it! I didn't realize there was even a node directory in that package.

Thanks for all the help!

from mui-x.

LukasTy avatar LukasTy commented on July 22, 2024

@michelengelen Isn't it the same ESM problem as with all the @mui packages? 🤔
mui/material-ui#37335
#11016
#8849

from mui-x.

michelengelen avatar michelengelen commented on July 22, 2024

@michelengelen Isn't it the same ESM problem as with all the @mui packages? 🤔 mui/material-ui#37335 #11016 #8849

It certainly does seem like it. 🤔

from mui-x.

tcov189 avatar tcov189 commented on July 22, 2024

Thanks for looking at this @LukasTy and @michelengelen . I thought it might be related to the ESM problem, but thought it was weird that npm run dev works but npm run start doesn't.

from mui-x.

LukasTy avatar LukasTy commented on July 22, 2024

@tcov189 If I'm not mistaken, the setup of the Dev and Build environments in Vite is pretty different.
Have you tried vite-plugin-commonjs as a temporary workaround? 🤔

from mui-x.

tcov189 avatar tcov189 commented on July 22, 2024

@tcov189 If I'm not mistaken, the setup of the Dev and Build environments in Vite is pretty different.
Have you tried vite-plugin-commonjs as a temporary workaround? 🤔

Hmm I have never heard of that plugin. I will give that a whirl.

from mui-x.

tcov189 avatar tcov189 commented on July 22, 2024

@LukasTy Just tried using the vite-plugin-commonjs package, didn't seem to have any effect. I pushed that change up to my repro repo, maybe I am not configuring it properly?

from mui-x.

raskyer avatar raskyer commented on July 22, 2024

I confirm it's the same issue with AdapterDateFns and it's pretty annoying.

Works in dev, do not in production with start cmd.

from mui-x.

tcov189 avatar tcov189 commented on July 22, 2024

But this seems to work : https://stackoverflow.com/questions/78017516/vite-ssr-build-fails-with-mui-icons-and-date-time-picker

import { AdapterDayjs} from "@mui/x-date-pickers/node/AdapterDayjs";

Hmm that didn't work for me, I tried the import you provided and tried it using AdapterLuxon
image

from mui-x.

raskyer avatar raskyer commented on July 22, 2024

You need to remove the import commonjs from "vite-plugin-commonjs" from vite config

from mui-x.

github-actions avatar github-actions commented on July 22, 2024

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @tcov189?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

from mui-x.

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.