简体   繁体   English

Gatsby 本地构建与 AWS Amplify 构建不同?

[英]Gatsby local build different from AWS Amplify build?

I have a Gatsby site that is working perfectly fine when I build and serve on localhost, but when I push the code and check my AWS Amplify website (that is tracking the github repo), it's behaving very differently.我有一个 Gatsby 网站,当我在 localhost 上构建和服务时,它工作得非常好,但是当我推送代码并检查我的 AWS Amplify 网站(即跟踪 github 存储库)时,它的行为就大不相同了。 For example, on my local production build, all the links are working properly and view page source shows HTML.例如,在我的本地生产版本中,所有链接都正常工作,查看页面源代码显示 HTML。

However, on my Amplify link, only some of the link paths are working, and view page source is not showing any HTML for any of the pages.但是,在我的 Amplify 链接上,只有一些链接路径有效,并且查看页面源没有显示任何页面的任何 HTML。 I assume there must be some kind of difference between the way it's being built on my local machine and on Amplify, but I'm not sure exactly where the exact problem is lying.我认为在我的本地计算机和 Amplify 上构建它的方式肯定存在某种差异,但我不确定确切的问题出在哪里。

In theory, since they're both production builds and not development, they should be behaving the same way?从理论上讲,由于它们都是生产版本而不是开发版本,因此它们的行为方式应该相同吗?

I assume there must be some kind of difference between the way it's being built on my local machine and on Amplify, but I'm not sure exactly where the exact problem is lying.我认为在我的本地计算机和 Amplify 上构建它的方式肯定存在某种差异,但我不确定确切的问题出在哪里。

I also think so.我也这么认为。 These kinds of issues (different behavior between environments) are usually related to Node versions.这些类型的问题(环境之间的不同行为)通常与 Node 版本有关。 hence the installed dependencies version differs between environments.因此安装的依赖项版本因环境而异。

In your case, check the current local version by running node -v and set the version to AWS Amplify (it uses nvm underlying).在您的情况下,通过运行node -v检查当前本地版本并将版本设置为 AWS Amplify(它使用nvm底层)。

You can follow one of the multiples approaches suggested in: How to change Node Version in Provision Step in Amplify Console您可以遵循以下建议的多种方法之一: 如何在 Amplify 控制台的配置步骤中更改节点版本

frontend:
  phases:
    preBuild:
      commands:
        - nvm install 10

Change 10 for your local version.10更改为您的本地版本。

Gatsby is a static site generator if you are adding new pages separately as an html link, at the build time it will be removed. Gatsby 是 static 站点生成器,如果您要单独添加新页面作为 html 链接,在构建时它将被删除。 You need to add them under the pages folder as a react component itself and use Link from gatsby to navigate across the pages您需要将它们添加到 pages 文件夹下作为反应组件本身,并使用 gatsby 中的 Link 浏览页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM