google-app-engine - Google App Engine 标准环境与 next/image 兼容吗?

标签 google-app-engine google-cloud-platform next.js nextjs-image

我在 Cloud Storage 渲染之前使用 imagekit.io CDN 和 next/image 组件。我之前在网上看到 next/image 与 GAE 标准环境不兼容。这让我担心......即使它正在工作,我想知道是否存在某种低效率,因为 next 无法缓存/tmp 之外的图像。 next/image 对我来说就像一个神奇的黑匣子。

next.config.js

const nextConfig = {
  experimental: {
    externalDir: true
  },
  reactStrictMode: true,
  images: {
    domains: ["ik.imagekit.io"]
  },
  distDir: "build"
};

module.exports = nextConfig;

目前还不能选择转向 Flex。我需要知道是否应该离开下一个/图像。

最佳答案

TL; DRGoogle App Engine 标准版对于 Next 来说并不是一个不错的选择


正如您在 tutorial 中指出的那样:

Nextjs Features like Image Component with Optimization, Incremental Static Regeneration requires nextjs cache folder to be read/written on runtime. But our Standard Environment has read and write access only to the /tmp directory.

由于无法在运行时写入的限制,不适合在 App Engine Standard 上使用 next/image 组件。此结论基于 Google App Engine Standard 和 NextJS 的官方文档

NextJS (next/image)

Images are optimized dynamically upon request and stored in the <distDir>/cache/images directory. The optimized image file will be served for subsequent requests until the expiration is reached.

Google App Engine Standard :

All files in this directory are stored in the instance's RAM, therefore writing to /tmp takes up system memory. In addition, files in the /tmp directory are only available to the app instance that created the files. When the instance is deleted, the temporary files are deleted.

这似乎是使用某些 NextJS 组件的开发人员之间的常见问题,需要写入 /cache在 App Engine Standard 上运行的文件夹,如本 GitHub discussion 所示:

Currently, the image optimiser caches images locally, in the servers filesystem, typically under .next/cache/images. While this is fine on some platform, it's not uncommon for managed deployment target to restrict write access to the filesystem (e.g. Google App Engine only provides write access to an in-memory /tmp folder) ... Currently, the only option we have to use next image optimization within Google App Engine is to use a custom server, override the handler for _next/images with an handler that does exactly the same as the image optimizer

关于这个GitHub issue :

Did you have a solution for this one? Considering moving our marketing site to AWS temporarily over this. Can't use next/image on GCP GAE.

If you really need to deploy to GCP GAE, you can set your application to a flex environment.

另请参阅:

关于google-app-engine - Google App Engine 标准环境与 next/image 兼容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71429343/

相关文章:

java - 将动态 URL 路由到 App Engine Java 中的静态文件

kubernetes - 云函数-连接Kubernetes容器

javascript - 在 header 组件 Next.js React 中渲染 Prop

python - 无法在 python 子进程中使用 gcloudcompute ssh 命令

javascript - 在带有以太 JS 的 Next Js 中使用 window.ethereum 时出错

javascript - 如何在 NEXT JS 中的路由之间传递状态?

python - 使用 Group By 从 appengine 数据存储中获取记录

python - 如何从外部站点检查用户是否喜欢 facebook 上的给定页面?

node.js - 在 Google Compute Engine 上自动安装 FFMPEG (Debian Wheezy 7.8)

google-cloud-platform - GCP 授予服务帐户使用 Deployment Manager 写入 GCS 存储桶的权限