Gatsby: _styledComponents.ServerStyleSheet 不是构造函数错误

创建于 2017-12-14  ·  3评论  ·  资料来源: gatsbyjs/gatsby

描述

为我的 github 页面运行 yarn deploy 时出现此 webpack 错误。

"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.

我正在使用gatsby-plugin-styled-components: "2.0.2"styled-components: "2.2.4"

gatsby-pluging-styled-components 应该处理过 SSR 吧? 还是我仍然需要手动配置它? 几个月前,当我部署我的 github 页面的第一个版本时,它运行良好。

最有用的评论

对于从谷歌来到这里的任何人......
确保@material-ui/core/styles 实际导出 ServerStyleSheets

这让我意识到我正在运行旧的 material-ui/core (3.9.x)
通过升级到 4.5.1 修复

所有3条评论

问题可以关闭。 意识到它是因为我没有为样式组件安装对等依赖项。

@jaanhio你能解释一下你是如何解决这个问题的吗? 我也遇到了同样的错误。

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)

对于从谷歌来到这里的任何人......
确保@material-ui/core/styles 实际导出 ServerStyleSheets

这让我意识到我正在运行旧的 material-ui/core (3.9.x)
通过升级到 4.5.1 修复

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

timbrandin picture timbrandin  ·  3评论

rossPatton picture rossPatton  ·  3评论

jimfilippou picture jimfilippou  ·  3评论

ghost picture ghost  ·  3评论

signalwerk picture signalwerk  ·  3评论