【问题标题】:Gatsby Styled Components plugin: window is not definedGatsby Styled Components 插件:未定义窗口
【发布时间】:2021-06-27 04:00:38
【问题描述】:

我的 Gatsby with Sanity 应用程序在运行 npm run build 时收到以下错误:

 WebpackError: ReferenceError: window is not defined (from plugin: gatsby-plugi
  n-styled-components)

似乎是外部包gatsby-plugin-styled-components 在某处使用window。我尝试用此处描述的虚拟模块替换https://www.gatsbyjs.com/docs/debugging-html-builds/#fixing-third-party-modules,但我的样式组件不起作用,所以它不是解决方案.

也许我在不支持的地方使用了样式化组件技术?我查看了不同的 gatsby/styled components 示例 repo,但找不到区别。

你可以在这里找到回购:https://github.com/sanderdebr/sanity-gatsby-portfolio

【问题讨论】:

    标签: gatsby styled-components sanity


    【解决方案1】:

    这是因为您的项目或 gatsby-plugin-styled-components 在某处使用 styled-components@5.2.2,这是使用 window 的损坏版本。

    该问题已在 SC Github 上跟踪:https://github.com/styled-components/styled-components/issues/3444

    我建议你更新到 styled-components@5.2.3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-04
      • 2020-12-19
      • 2018-10-13
      • 2020-11-26
      • 2020-12-30
      • 2021-01-03
      • 2021-02-26
      • 1970-01-01
      相关资源
      最近更新 更多