Skip to content

_styledComponents.ServerStyleSheet is not a constructor error #3209

Closed

Description

@jaanhio

Description

I am getting this webpack error when running yarn deploy for my github page.

"deploy": "gatsby build --prefix-paths && gh-pages -d public",

error Building static HTML for pages failed`

`See our docs page on debugging HTML builds for help https://goo.gl/yL9lND`

  `16 |       setHeadComponents = _ref.setHeadComponents;
  17 |
> 18 |   var sheet = new _styledComponents.ServerStyleSheet();
     | ^
  19 |
  20 |   var app = _react2.default.createElement(
  21 |     _styledComponents.StyleSheetManager,`


`WebpackError: _styledComponents.ServerStyleSheet is not a constructor`

  - gatsby-ssr.js:18 Object.exports.replaceRenderer
    ~/gatsby-plugin-styled-components/gatsby-ssr.js:18:1

  - api-runner-ssr.js:23
    .cache/api-runner-ssr.js:23:41


  - api-runner-ssr.js:21 module.exports
    .cache/api-runner-ssr.js:21:25

  - static-entry.js:113 module.exports
    .cache/static-entry.js:113:3

  - static-entry.js:99 Function.Promise.fromNode.Promise.fromCallback
    .cache/static-entry.js:99:20





error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I am using gatsby-plugin-styled-components: "2.0.2"and styled-components: "2.2.4".

gatsby-pluging-styled-components should have handled the SSR right? or do i still have to configure it manually? it worked fine a few months ago when i deployed the first version of my github page.

Activity

  1. jaanhio commented on Dec 14, 2017

    @jaanhio
    Author

    Issue can be closed. Realized its because i did not install the peer dependency for styled-components.

  2. harmeetv commented on Nov 23, 2019

    @harmeetv

    @jaanhio Can you explain how did you solved this? I am also getting same kind of error.

    TypeError: _material_ui_core_styles__WEBPACK_IMPORTED_MODULE_10__.ServerStyleSheets is not a constructor
        at eval (webpack:///./server/helpers/renderer.js?:37:16)
        at eval (webpack:///./server/index.js?:54:81)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)
    
  3. Boogieman66 commented on Mar 11, 2020

    @Boogieman66

    For anyone coming here from google....
    make sure @material-ui/core/styles actually exports ServerStyleSheets

    this lead me to realize I'm running an older material-ui/core (3.9.x)
    fixed by upgrading to 4.5.1

  4. sanjsanj commented on May 18, 2021

    @sanjsanj

    Just had the same issue on my Next build, I ended up with the alpha release of "@material-ui/core": "^5.0.0-alpha.33" in my package.json, I swapped it over to the latest stable release "^4.11.4" and it works now.

  5. ocodista commented on May 18, 2021

    @ocodista

    Same thing here @sanjsanj. My next build command was working until this latest release of 5.0.0-alpha.33 but after the update it crashes.

    Error message:
    Error occurred prerendering page "/auth/login". Read more: https://nextjs.org/docs/messages/prerender-error
    TypeError: material_ui_core_styles__WEBPACK_IMPORTED_MODULE_3_.ServerStyleSheets is not a constructor
    at Function.exports.modules.1225.MyDocument.getInitialProps

  6. soroosh123rf commented on May 27, 2021

    @soroosh123rf

    I had the same problem and changed the import like this: import { ServerStyleSheets } from '@material-ui/styles' and now it's working fine again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions