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

Next.js Example Fails SSR #20926

Closed
2 tasks done
Olliebrown opened this issue May 6, 2020 · 4 comments
Closed
2 tasks done

Next.js Example Fails SSR #20926

Olliebrown opened this issue May 6, 2020 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@Olliebrown
Copy link

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

Current Behavior 😯

When following the instructions for downloading, installing, and running the dev version of the Next.js example in the material-ui/examples folder, the index page fails to compile and throws the error ReferenceError: Element is not defined from inside the react-transition-group module (a direct dependency of @material-ui/styles). This happens as soon as you run npm run dev and try to visit localhost:3000

Full error generated is:

ReferenceError: Element is not defined
    at Object.<anonymous> (/sandbox/node_modules/react-transition-group/cjs/Transition.js:452:44)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/sandbox/node_modules/react-transition-group/cjs/CSSTransition.js:14:42)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)

Expected Behavior 🤔

The example page should render on the server successfully and be delivered to the client.

Steps to Reproduce 🕹

Easy way to reproduce:

It is broken when running in the codesandbox.io example in the same way I observe on my local machine.

Context 🔦

My goal is to get a working Material-UI example in Next.js. So far, I am just trying to get a working example of Next and MUI cooperating.

Your Environment 🌎

Latest everything, just use the code sandbox :-)

@Olliebrown
Copy link
Author

Looks like the true source of this is likely the latest version of react-transition-group module. See reactjs/react-transition-group#618

I tried building the latest Gatsby SSR example too and eventually hit the same error (after I added 'react-jss' as a dependency).

@WinmezzZ
Copy link
Contributor

WinmezzZ commented May 6, 2020

Looks like the true source of this is likely the latest version of react-transition-group module. See reactjs/react-transition-group#618

I tried building the latest Gatsby SSR example too and eventually hit the same error (after I added 'react-jss' as a dependency).

so how to fix it?

@Olliebrown
Copy link
Author

Olliebrown commented May 6, 2020

No idea what the long term fix is (that's really up to react-transition-group's maintainers). To work around, you need to get rid of the 'Element' variable it is complaining about (it doesn't exist server-side).

Workaround I'm using (from comments on reactjs/react-transition-group#618):

  • edit node_modules/react-transition-group/cjs/Transition.js
  • Change lines 451 - 453 to this:
  nodeRef: _propTypes.default.shape({
    current: _propTypes.default.instanceOf(typeof Element === 'undefined' ? function(){} : Element)
  }),

This is very manual and a pretty delicate fix as updates to the node modules will wipe out the change.

@oliviertassinari oliviertassinari added the external dependency Blocked by external dependency, we can’t do anything about it label May 6, 2020
@eps1lon
Copy link
Member

eps1lon commented May 6, 2020

Duplicate of #20924

@eps1lon eps1lon marked this as a duplicate of #20924 May 6, 2020
@eps1lon eps1lon added duplicate This issue or pull request already exists and removed external dependency Blocked by external dependency, we can’t do anything about it labels May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants