gatsby: updating gatsby-plugin-sharp from 2.8.0 to 2.9.0 breaks build
Description
error pngload: non-recoverable state
pngload: non-recoverable state
vips2png: unable to write to target target
Error: pngload: non-recoverable state
pngload: non-recoverable state
vips2png: unable to write to target target
not finished run page queries - 1.474s
not finished Generating image thumbnails - 1.299s
error Command failed with exit code 1.
I can up- and downgrade repeatedly. v2.8.0 always works, v2.9.0 always errors.
Steps to reproduce
This is a complex app. I have no idea if this happens generally.
- clone https://github.com/barbalex/apf2
- check that gatsby-plugin-sharp is set to v2.8.0
yarn && yarn dev> should succeed- set gatsby-plugin-sharp to v2.9.0 > should error
Expected result
Build should succeed
Actual result
see above
Environment
Run gatsby info --clipboard in your project directory and paste the output here.
$ yarn gatsby info --clipboard
yarn run v1.22.5
$ C:\Users\alexa\apf2\node_modules\.bin\gatsby info --clipboard
System:
OS: Windows 10 10.0.19042
CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
Binaries:
Node: 15.0.1 - ~\AppData\Local\Temp\yarn--1605869962190-0.9665755114141126\node.CMD
Yarn: 1.22.5 - ~\AppData\Local\Temp\yarn--1605869962190-0.9665755114141126\yarn.CMD
npm: 7.0.3 - C:\Program Files\nodejs\npm.CMD
Languages:
Python: 2.7.17
Browsers:
Chrome: 86.0.4240.198
Edge: Spartan (44.19041.423.0), Chromium (86.0.622.69)
npmPackages:
gatsby: 2.27.0 => 2.27.0
gatsby-cli: 2.14.0 => 2.14.0
gatsby-image: 2.6.0 => 2.6.0
gatsby-plugin-create-client-paths: 2.5.0 => 2.5.0
gatsby-plugin-eslint: 2.0.8 => 2.0.8
gatsby-plugin-manifest: 2.7.0 => 2.7.0
gatsby-plugin-offline: 3.5.0 => 3.5.0
gatsby-plugin-react-helmet: 3.5.0 => 3.5.0
gatsby-plugin-sharp: 2.8.0 => 2.8.0
gatsby-plugin-styled-components: 3.5.0 => 3.5.0
gatsby-plugin-typography: 2.7.0 => 2.7.0
gatsby-remark-autolink-headers: 2.6.0 => 2.6.0
gatsby-remark-copy-linked-files: 2.5.0 => 2.5.0
gatsby-remark-embed-video: 3.0.10 => 3.0.10
gatsby-remark-emojis: 0.4.3 => 0.4.3
gatsby-remark-external-links: 0.0.4 => 0.0.4
gatsby-remark-images: 3.6.0 => 3.6.0
gatsby-remark-images-medium-zoom: 1.7.0 => 1.7.0
gatsby-remark-numbered-footnotes: 1.0.1 => 1.0.1
gatsby-remark-prismjs: 3.8.0 => 3.8.0
gatsby-source-filesystem: 2.6.0 => 2.6.0
gatsby-transformer-remark: 2.11.0 => 2.11.0
gatsby-transformer-sharp: 2.7.0 => 2.7.0
Done in 1.99s.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 46 (15 by maintainers)
I found the issue to be multiple versions of sharp. If I upgraded
gatsby-plugin-manifest(to 2.10.0)gatsby-plugin-sharp(to 2.12.0)gatsby-transformer-sharp(to 2.10.0)Then when running
yarn why sharpI only hadsharp@0.27.0and things seem to work as expected.@vladar In gatsby-config.js I changed
'gatsby-plugin-sharp'to:But I still get the same error when using
"gatsby-plugin-sharp": "2.10.0".Having the same issue
EDIT: I added this in
package.json. This fixed the problem for me:Uups. Suddenly the following error breaks the build again:
Here the result from
gatsby info --clipboard:and here an excerp from my
gatsby-config:I’ve created an internal ticket to catch these errors and log a more friendly message along the lines of “Could not process the image ‘foo.png’ because it is corrupt”
Also,
gatsby-plugin-sharpsupportsfailOnErroroption:https://www.gatsbyjs.com/plugins/gatsby-plugin-sharp/#allow-build-to-continue-on-image-processing-error
Was introduced in #27345
I have just encountered the same problem (on Mac OS Cataline - pre M1), combination of few things above worked for me, it might be that only one of those three things was required, nevertheless at this point both
gatsby developand `gatsby buildswitching to
gatsby-plugin-sharp@3.1.2adding to package.json
gatsby-config.jssame issue on m1 mac, adding resolutions did not resolve.
When updating gatsby-plugin-sharp from v2.8.0 to 2.9.0, I would expect:
But that is exactly what is happening. I understand that at least one of the images used on my project are technically “corrupted”. But that should not stop the project from building.
Actually, the weird thing is that I have managed to build gatsby with one of the recent gatsby-plugin-sharp versions. And when that worked, the images kept working as well. But then suddenly the build started failing again. In the meantime I had changed nothing at all.
So the image does show when using gatsby-plugin-sharp version 2.8.0 and also sometimes when building with a higher version.
For those in this thread, make sure you have the following packages all on the same version:
gatsby-plugin-manifestgatsby-plugin-sharpgatsby-transformer-sharpMy issue was that I had
gatsby-transformer-sharp+gatsby-plugin-sharpat the latest, but I didn’t updategatsby-plugin-manifest. After updatinggatsby-plugin-manifesti no longer had the build error. I hope this helps someone ❤️That’s the reason. It doesn’t support AVIF until, I think 0.27. What happens if you remove it now?
I found that the
failOnErroroption is not passed tosharp()for the creation of Base64 images. I opened a PR to fix this issue: https://github.com/gatsbyjs/gatsby/pull/29254@barbalex I agree, so I’ll have a look at this. I would expect that a corrupt image would warn but continue building.
@ascorbic To really answer your question explicitly: I realize you can’t influence the fact that so far working images are now technically corrupt. But I expect the gatsby build to still work (while probably telling me about the corrupt images as it does quite nicely).
What would you do if you have a Site where users can upload images. So you now have thousands of them, without a lot of control over the pre-processing of the images the users upload. Suddenly, when updating one of dozens of dependencies of gatsby, your site build breaks and can never be built again.
What now?
@mlenser Thanks for helping.
Unfortunately this does not seem to be the cause in my project.
Thanks, @mlenser! I was dealing with the same issue, and thanks to you, my gatsby site is working within only a few minutes of searching the web.
So that is just the first image that breaks the build. I would probably have to replace lots of images to get my build to work again 😢
This image contains an ICC (colour) profile with an invalid checksum.
The venerable libpng, as used by Chrome, ignores this error.
As of v0.26.0, sharp has started to provide the more modern libspng, hence the need to now explicitly confirm you are willing to accept/trust this image via
failOnError: false.Thanks for the report, I did run it locally and confirmed I see same result locally.
Only thing to keep in mind that repo as it as right now have mix of incompatible sharp versions:
Which result in
Crash almost immediately (at least on MacOS) - using yarn resolutions in package.json to set
sharpversion to either0.25.4(it works) or0.26.3(it crashes) was my way around this.It feels like issue is in
sharppackage - given that toggling betweensharpversion and not even touchinggatsby-plugin-sharpversion cause the failure / successful builds.Some initial details - here is example image data and arguments we pass to sharp where it fails (I’m not saying it’s faulty image - it’s just a way to be able to do minimal reproduction we could report in
sharprepository):Those are arguments we pass to
fluidfunction in https://github.com/gatsbyjs/gatsby/blob/fe18a18812276c19c2bef654f08039f1037113f7/packages/gatsby-remark-images/src/index.js#L151-L156