我在 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.
block 引用>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/