Gatsby构建Webpack失败并带有手写笔

时间:2020-11-02 13:14:46

标签: css reactjs webpack gatsby stylish

运行gatsby build时出现此错误:

failed Building static HTML for pages - 10.179s

 ERROR #95313 

Building static HTML failed

See our docs page for more info on this error: https://gatsby.dev/debug-html


  343 |         for (c = []; b < a; ++b) {
  344 |           for (var n = 0; n < m; ++n) {
> 345 |             c[v++] = Z(d[n] + ' ', h[b], e).trim();
      | ^
  346 |           }
  347 |         }
  348 | 


  WebpackError: The module '/node_modules/canvas/build/Release/canvas.node'
  
  - stylis.esm.js:345 
    node_modules/@emotion/stylis/dist/stylis.esm.js:345:1
  
  - stylis.esm.js:151 
    node_modules/@emotion/stylis/dist/stylis.esm.js:151:1
  
  - stylis.esm.js:175 
    node_modules/@emotion/stylis/dist/stylis.esm.js:175:1
  
  - stylis.esm.js:286 
    node_modules/@emotion/stylis/dist/stylis.esm.js:286:1
  
  - stylis.esm.js:151 
    node_modules/@emotion/stylis/dist/stylis.esm.js:151:1
  
  - stylis.esm.js:175 
    node_modules/@emotion/stylis/dist/stylis.esm.js:175:1
  
  - stylis.esm.js:286 
    node_modules/@emotion/stylis/dist/stylis.esm.js:286:1
  
  - stylis.esm.js:151 

如何解决?运行gatsby development时没有错误。

2 个答案:

答案 0 :(得分:0)

更新gatsby-config.js以包含插件gatsby-plugin-emotion:

module.exports = {
  plugins: [
    `gatsby-plugin-emotion`,
  ],
}

这需要重新启动gatsby开发过程。

答案 1 :(得分:0)

Color.FromKnownColor(CType(rng.Next(28, 168),KnownColor))中添加此代码段:

gatsby-node.js

有一个试图访问global objects such as window or document in your SSR (Server-Side Rendering)的程序包,其中显然没有定义(甚至存在),因为exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => { if (stage === "build-html") { actions.setWebpackConfig({ module: { rules: [ { test: /canvas/, use: loaders.null(), }, ], }, }) } } 发生在节点服务器中,而gatsby-build发生在浏览器端, gatsby develop所在的位置以及编译时间。使用上面的代码段,您将在Webpack转换代码时向有问题的模块添加window加载程序。

规则测试是一个与null中的文件夹名称匹配的正则表达式(因此,括号为/)。输出错误显示一个node_modules问题,但您可能需要将其更改为canvas