【发布时间】:2022-10-14 14:03:37
【问题描述】:
所以我无法构建我的 gatsby 应用程序,因为它对 window.xml 有很多依赖。许多组件是根据浏览器窗口的宽度构建的。 在“gatsby build”命令之后,我得到了 WebpackError: ReferenceError: window is not defined。 我在互联网上找到了将以下代码粘贴到 gatsby-node.js 中的解决方案:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === 'build-html' || stage === 'develop-html') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /node_modules/,
use: loaders.null(),
},
],
},
});
}
};
但是在重建应用程序时出现此错误:
<w> [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item 'Compilation/modules|json|C:\Users\Damian\Documents\Ossolinsky\app\node_modules\null-loader\dist\cjs.js??ruleSet[1].rules[13].use!C:\Users\Damian\Documents\Ossolinsky\app\node_modules\gatsby\package.json': No serializer registered for JSONParseError
ERROR #98123 WEBPACK
Generating SSR bundle failed
Unexpected end of JSON input while parsing empty string
File: node_modules\gatsby\package.json
not finished Building HTML renderer - 1.257s
【问题讨论】: