Gatsby: _styledComponents.ServerStyleSheet is not a constructor error

Created on 14 Dec 2017  ·  3Comments  ·  Source: gatsbyjs/gatsby

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.

Most helpful comment

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

All 3 comments

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

@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)

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kalinchernev picture kalinchernev  ·  3Comments

timbrandin picture timbrandin  ·  3Comments

totsteps picture totsteps  ·  3Comments

KyleAMathews picture KyleAMathews  ·  3Comments

magicly picture magicly  ·  3Comments