【问题标题】:Gatsby-ssr and React context crashGatsby-ssr 和 React 上下文崩溃
【发布时间】:2020-06-18 20:54:29
【问题描述】:

我遇到了一个问题,似乎使用 gatsby-ssr 和 react context 似乎使我的构建失败。
我收到这些错误 - 并且发现问题出在 gatsby ssr 文件上。通过删除这个构建工作?使用 Gatsby,内容丰富。

const React = require("react")
const GlobalContextProvider = require('./src/context/GlobalContext')
exports.wrapRootElement = ({ element }) => {
  return (
    <GlobalContextProvider>
      {element}
    </GlobalContextProvider>
  )
}

这是错误信息

Building static HTML failed for path 


  WebpackError: Minified React error #130; visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=object&args[]= for the full message or use the non-minified dev environment   for full errors and additional helpful warnings.

  - build-html.js:110 doBuildPages
    [slut]/[gatsby]/dist/commands/build-html.js:110:24

  - build-html.js:124 async buildHTML
    [slut]/[gatsby]/dist/commands/build-html.js:124:3

  - build.js:200 async build
    [slut]/[gatsby]/dist/commands/build.js:200:5

【问题讨论】:

    标签: javascript reactjs gatsby


    【解决方案1】:

    如果您以与代码示例相同的方式导出 GlobalContext,则将值附加到“exports”对象中,因此您必须从中提取。

    这里有 2 个导出示例:

    导出文字

    // file1.js
    module.exports = 'Hello world';
    
    // file2.js
    var msg = require('./file1.js');
    
    console.log(msg); // Hello world
    

    导出对象

    // file1.js
    exports.globalContext = 'Hello world';
    
    // file2.js
    var context = require('./file1.js');
    
    console.log(context.globalContext); // Hello world
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 2018-12-26
      • 2021-06-07
      • 2019-06-01
      • 2020-06-27
      • 1970-01-01
      相关资源
      最近更新 更多