aws amplify nextjs s-s-r不想刷新

Posted

技术标签:

【中文标题】aws amplify nextjs s-s-r不想刷新【英文标题】:aws amplify nextjs s-s-r does not want to refresh 【发布时间】:2021-08-23 10:11:24 【问题描述】:

我正在使用 NextJS 测试 Amplify s-s-r。我的本地环境运行良好:我的内容每 60 秒正确刷新一次,但是当我在 AWS AMPLIFY (eu-west-2) 上发布内容时不想刷新。

这里是我使用的来源:https://aws.amazon.com/fr/blogs/mobile/host-a-next-js-s-s-r-app-with-real-time-data-on-aws-amplify/

这里有一些配置文件:

package.json


  "name": "poc",
  "version": "0.1.0",
  "private": true,
  "scripts": 
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  ,
  "dependencies": 
    "aws-amplify": "^4.0.3",
    "next": "10.2.3",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "yarn": "^1.22.10"
  

index.js

import  Amplify  from "aws-amplify";
import awsExports from "../aws-exports";
Amplify.configure( ...awsExports, s-s-r: true );

export default function Home(date) 

  return (
      <>
        <b>date</b>
      </>
  );


export async function getStaticProps()
  return 
    props: 
      page,
      date:(new Date()).toString()
    ,
      revalidate: 60
  

aws-exports.js

const awsmobile = 
    "aws_project_region": "eu-west-2"
;


export default awsmobile;

项目配置.json



  "projectName": "monpoc",
  "version": "3.0",
  "frontend": "javascript",
  "javascript": 
    "framework": "react",
    "config": 
      "SourceDir": ".",
      "DistributionDir": "build",
      "BuildCommand": "npm run-script build",
      "StartCommand": "npm run-script start"
    
  ,
  "providers": [
    "awscloudformation"
  ]

2021-06-05T17:48:22.315Z [INFO]: Page                              Size     First Load JS
                                 ┌ ● / (ISR: 60 Seconds)           1.67 kB        64.7 kB
                                 ├   /_app                         0 B              63 kB
                                 ├ ○ /404                          3.06 kB        66.1 kB
                                 └ λ /api/hello                    0 B              63 kB
                                 + First Load JS shared by all     63 kB
                                 ├ chunks/framework.c38115.js    42 kB
                                 ├ chunks/main.71948a.js         19.4 kB
                                 ├ chunks/pages/_app.9e3669.js   571 B
                                 ├ chunks/webpack.189c53.js      994 B
                                 └ css/fb7e07ce64500530d3fc.css  194 B
2021-06-05T17:48:22.315Z [INFO]: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
                                 ○  (Static)  automatically rendered as static html (uses no initial props)
                                 ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
                                 (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
2021-06-05T17:48:23.011Z [INFO]: Done in 14.73s.
2021-06-05T17:48:23.016Z [INFO]: Starting s-s-r Build...
2021-06-05T17:50:09.606Z [INFO]: s-s-r Build Complete.
2021-06-05T17:50:10.659Z [INFO]: # Completed phase: build
2021-06-05T17:50:10.660Z [INFO]: ## Build completed successfully
2021-06-05T17:50:10.661Z [INFO]: # Starting caching...
2021-06-05T17:50:10.759Z [INFO]: Creating cache artifact...
2021-06-05T17:50:14.604Z [INFO]: # Cache artifact is: 238MB
2021-06-05T17:50:14.673Z [INFO]: # Uploading cache artifact...
2021-06-05T17:50:17.098Z [INFO]: # Caching completed
2021-06-05T17:50:17.125Z [INFO]: No custom headers found.
2021-06-05T17:50:17.127Z [INFO]: # Starting build artifact upload process...
2021-06-05T17:50:19.102Z [INFO]: # Build artifact is: 18MB
2021-06-05T17:50:19.116Z [INFO]: # Build artifact is: 18MB
2021-06-05T17:50:19.117Z [INFO]: # Uploading build artifact '__artifactsHash.zip'...
2021-06-05T17:50:19.207Z [INFO]: # Uploading build artifact '__artifacts.zip'...
2021-06-05T17:50:19.531Z [INFO]: # Build artifact upload completed
2021-06-05T17:50:19.532Z [INFO]: # Starting environment caching...
2021-06-05T17:50:19.532Z [INFO]: # Environment caching completed
Terminating logging...

我卡住了:“2021 年 6 月 5 日星期六 17:49:26 GMT+0000(协调世界时)”

s-s-r 模式似乎可以工作,但如何正确应用 ISR

提前感谢您的帮助

【问题讨论】:

我遇到了类似的问题。你有什么办法吗? 对此的任何解决方案。我被困在我的生产部署中。面临同样的问题 【参考方案1】:

对于下一个 v11 问题是,如果您使用了环境变量中的重新验证间隔,则 Lamba 函数无法访问该环境变量。我观察到,如果我对重新验证间隔进行硬编码,则页面会使用 ISR 正确刷新。

对于 Next v9 Next v9 没有遇到这个问题。

【讨论】:

以上是关于aws amplify nextjs s-s-r不想刷新的主要内容,如果未能解决你的问题,请参考以下文章

NextJS 与 Aws Amplify 部署错误

在 AWS 上使用 NextJS s-s-r 部署 React 应用程序的最便宜方法? [关闭]

为啥 AWS amplify 无法识别更新的节点版本?

没有当前用户 - getServerSideProps Next JS 和 AWS Amplify

NextJS 上的 s-s-r 是如何工作的?

Graphql - 无权访问来自 AWS AppSync Amplify 控制台的错误消息