【发布时间】:2020-03-17 08:36:55
【问题描述】:
我正在使用 Gatbsy、Contentful CMS 和 Netlify 构建网站。 它看起来很棒并且可以在本地工作,但是我在使用 tracedSVG 选项的流体图像方面遇到了问题。 Netlify 部署过去有时可以工作,随着我向项目中添加更多图像,现在不断出现以下错误(并不总是在同一页面中):
10:53:45 AM: The GraphQL query from /opt/build/repo/src/pages/index.js failed.
10:53:45 AM: Errors:
10:53:45 AM: VipsJpeg: Corrupt JPEG data: premature end of data segment
10:53:45 AM: VipsJpeg: out of order read at line 544
10:53:45 AM: GraphQL request:54:3
10:53:45 AM: 53 | fragment GatsbyContentfulFluid_tracedSVG on ContentfulFluid {
10:53:45 AM: 54 | tracedSVG
10:53:45 AM: | ^
10:53:45 AM: 55 | aspectRatio
有时
error
The GraphQL query from /opt/build/repo/src/pages/index.js failed.
Errors: Input file contains unsupported image format
GraphQL request:40:3
| fragment GatsbyContentfulFluid_tracedSVG on ContentfulFluid {
| tracedSVG
| ^
| aspectRatio
在极少数情况下
Errors:
VipsJpeg: Empty input file
(最后一个没有意义,因为图像存在于 Contentful 中并且是我的内容模型的必填字段)
如前所述; GraphQL 查询从本地的 Contentful 工作中检索 tracedSVG 图像。我的代码如下:
import React from "react"
import { Link, graphql } from "gatsby"
import Img from "gatsby-image"
const IndexPage = ({ data: { allContentfulIndexPage }) => {
const { myImage } = allContentfulIndexPage.edges[0].node
return (
<div>
{...someIrrelevantCodeToTheQuestion}
<Img fluid={myImage.fluid}/>
</div>
)
}
export default IndexPage
export const query = graphql`
query IndexPageQuery {
allContentfulIndexPage {
edges {
node {
myImage {
fluid {
...GatsbyContentfulFluid_tracedSVG
}
}
}
}
}
}
`
通过使用 GraphiQL,我发现在本地使用 tracedSVG 而不是 ...GatsbyContentfulFluid_tracedSVG 也可以在本地工作,但它在生产/Netlify 环境中崩溃是一样的。我考虑使用png 图像而不是jpg,因为这些错误表明文件本身有问题,尽管它们在本地渲染得很好,但 png 大小的等效值会减慢网站速度(100kB 的 jpg 图像在 png 中大约为 900kb) .
在生产中使用 jpg 图像渲染 tracedSVG 是否有人遇到过同样的问题?如果是这种情况,您是如何解决以阻止经常性崩溃的?谢谢。
【问题讨论】:
-
很确定这是一个未解决的错误问题,一个是 maxHeight 和
maxWidth没有在traceSVG. The logic from fluid should be copied totraceSVG` 中使用,即使技术上没有必要。试试fluid(maxWidth: 500, maxHeight: 500)看看它是否可以构建。另外我认为tracedSVG的记忆存在问题。它通过文件名和参数进行记忆,而裁剪在fileArgs参数中设置。 -
嗨@NickC 感谢您的意见。我尝试使用
fluid(maxWidth: 500, maxHeight: 500)看看它是否能解决问题,但没有。在检查 graphQL 查询期间会出现此问题。我仍在摆弄不同的选择,但还没有找到有效的方法。正如你提到的,这可能是一个未解决的错误。
标签: gatsby netlify contentful fluid-images gatsby-image