如何解决Gatsby Cloud - 构建失败:WebpackError: /usr/src/app/www/public/render-page.js:4464
我在 Gatsby Cloud 上的构建遇到了一个问题,这让我很难过,而且我在网上找不到任何相关信息!
我有一个在本地(即在我的笔记本电脑上)运行良好的站点构建,但是在 Gatsby Cloud 上运行时始终会导致以下错误:
failed Building static HTML for pages - 0.302s
ERROR Building static HTML failed
5 | };
6 |
> 7 | module.exports["default"] = module.exports,module.exports.__esModule = true;
| ^
8 | return _setPrototypeOf(o,p);
10 |
9 | }
- setPrototypeOf.js:7
[project]/[@babel]/runtime/helpers/setPrototypeOf.js:7:3
WebpackError: /usr/src/app/www/public/render-page.js:4464
- utils.js:267
- utils.js:103
[project]/[@gatsbyjs]/reach-router/lib/utils.js:267:1
[project]/[@gatsbyjs]/reach-router/lib/utils.js:103:1
- utils.js:241
[project]/[@gatsbyjs]/reach-router/es/lib/utils.js:241:4
- history.js:48
[project]/[@gatsbyjs]/reach-router/lib/utils.js:127:1
- utils.js:127
[project]/[@gatsbyjs]/reach-router/es/lib/history.js:52:1
- history.js:52
[project]/[@gatsbyjs]/reach-router/es/lib/history.js:48:1
- extends.js:20
[project]/[@babel]/runtime/helpers/extends.js:20:1
[project]/[@gatsbyjs]/reach-router/lib/utils.js:166:1
- utils.js:166
not finished Caching HTML renderer compilation - 0.381s
not finished Caching JavaScript and CSS webpack compilation - 11.935s
ERROR Failed to compile: Error: Exited with code 1
超过 3 次尝试构建,webpack 错误的文件和行号始终相同。然而,由于我不是网络开发人员(这是一个我自愿参与的社区项目,没有专业的网络开发人员)而且我真的只是在复制和粘贴代码......我遇到了障碍在这里,不知道如何解决这个问题。我真的很感激任何帮助。特别是作为一个预算完全为零的社区项目,我无法在这里使用 Gatsby 的商业支持! ?
预先感谢任何人可以提供的帮助
解决方法
当某些内容在本地构建但不在任何服务器环境(在本例中为 Netlify 或 Gatsby Cloud)中时,通常是由 Node 环境之间的版本不匹配引起的。在这种情况下,你给了我线索:
我在本地使用的 Node 版本与 Gatsby Cloud 上使用的版本不同; 16.4.0 本地 vs. 12.22.1
这意味着您正在运行不同的依赖版本,导致两种环境中的行为不同。
在 Gatsby 的 Cloud 环境中,您可以将 Node version by setting the NODE_VERSION
环境变量自定义为 16.4.0
。那应该可以解决您的问题。因为根据文档,它默认为 12
:
NODE_VERSION
:指定您的项目应使用的 Node.js 版本。
例如,NODE_VERSION=10
。默认为 12。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。