Material-ui: @material-ui/core incompatible with next.js

Created on 27 Apr 2019  路  6Comments  路  Source: mui-org/material-ui

  • [x] This is not a v0.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.


When using next.js versions >= 8.0.5-canary.11 I am not able to use certain components of @material-ui/[email protected]. If I downgrade to @material-ui/[email protected] there is no issue.

On the flip side, I can use next.js versions <= 8.0.5-canary.10 with @material-ui/[email protected] (and proabably any other version)

The issue appears to only happen when I import and use a ListItem, though It's possible others have the same issue.

this seems to be the same issue but was closed

Additional notes:

  • everything works in development, it only breaks in production

Expected Behavior 馃


I should be able to build and start an app using a <ListItem> import and use the latest versions of next.js when using material-ui

Current Behavior 馃槸


I get a 500 error with the following output in the console:

TypeError: Cannot read property 'dense' of undefined                                                                                                                                                                                              
    at Object.children (/home/ubuntu/dev/mui-next/node_modules/@material-ui/core/ListItem/MergeListContext.js:27:31)                                                                                                                              
    at a.render (/home/ubuntu/dev/mui-next/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:44:64)
    at a.read (/home/ubuntu/dev/mui-next/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:41:58)
    at renderToString (/home/ubuntu/dev/mui-next/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:53:83)
    at render (/home/ubuntu/dev/mui-next/node_modules/next-server/dist/server/render.js:83:16)
    at renderPage (/home/ubuntu/dev/mui-next/node_modules/next-server/dist/server/render.js:201:20)
    at Function.value (/home/ubuntu/dev/mui-next/.next/server/static/NF5o8EJCIiIS3Bbj1tDFL/pages/_document.js:808:41)
    at Object.loadGetInitialProps (/home/ubuntu/dev/mui-next/node_modules/next-server/dist/lib/utils.js:42:35)
    at Object.renderToHTML (/home/ubuntu/dev/mui-next/node_modules/next-server/dist/server/render.js:207:36)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Steps to Reproduce 馃暪


Link: https://codesandbox.io/s/nrnx4p6q4p

repo: https://github.com/jaycenhorton/next-mui-errors

Context 馃敠

Your Environment 馃寧

| Tech | Version |
|--------------|---------|
| Material-UI | ^ v3.9.3 |
| React | 16.8.6 |
| next | ^ 8.0.5-canary.11 |

external dependency

Most helpful comment

All 6 comments

Is this issue present using the 4.0.0 alphas?

@jaycenhorton It shouldn't be an issue with Material-UI the list context has a default value: {}. The problem is fixed in v4.0.0-alpha.8. I can't explain what's wrong in v3 馃槺.

It seems to be a regression on Next.js side. next 8.0.4 works, next 8.1.0 doesn't.

Please, I am confused as to how to solve this problem "TypeError: Cannot read property 'dense' of undefined" in my code. I did not get how you guys solved it. It still occured in my code this morning

@samuelkurdz I believe you need to revert back to v8.0.4: https://github.com/zeit/next.js/releases/tag/v8.0.4.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tleunen picture tleunen  路  59Comments

garygrubb picture garygrubb  路  57Comments

illogikal picture illogikal  路  75Comments

damianobarbati picture damianobarbati  路  55Comments

mnajdova picture mnajdova  路  105Comments