【问题标题】:window is not defined in gatsby development env窗口未在 gatsby 开发环境中定义
【发布时间】:2021-09-24 16:30:46
【问题描述】:

Getting this error when i try to use react-spring-3d-carousel in gatsby

我也检查了平台上可用的其他解决方案,但没有一个对我有用。 我已将 gatsby-nodejs 设置为以下解决方案,但它不起作用。

exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
  if (stage === "build-html") {
    actions.setWebpackConfig({
      module: {
        rules: [{ test: /react-spring-3d-carousel/, use: loaders.null() }],
      },
    })
  }
}

但它仍然给我错误窗口没有定义。我试图从两周内解决这个错误,但没有一个解决方案对我有用。帮我解决这个问题。任何帮助将不胜感激。

【问题讨论】:

    标签: node.js reactjs gatsby


    【解决方案1】:

    尝试使用:

    exports.onCreateWebpackConfig = ({ loaders, getConfig }) => {
      const config = getConfig();
    
      config.module.rules = [
        {
          test: /react-spring-3d-carousel/,
          use: loaders.null(),
        },
      ];
    };
    

    方法基本相同,但适用于所有场景。您也可以尝试将其添加到您的条件中:

     if (stage === "build-html" || stage === "develop-html")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2021-06-27
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      • 2020-12-30
      • 2021-12-20
      相关资源
      最近更新 更多