gatsby: gatsby-plugin-sharp: WorkerError @2.6.27
Description
Error processing a .png file when running gatsby develop
Steps to reproduce
Upgrading gatsby-plugin-sharp to version 2.6.27
Expected result
Images would be queried as expected
Actual result
Environment
System: OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa) CPU: (8) x64 AMD Ryzen 7 2700U with Radeon Vega Mobile Gfx Shell: 5.0.17 - /bin/bash Binaries: Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node Yarn: 1.22.4 - /usr/bin/yarn npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm Languages: Python: 2.7.18 - /usr/bin/python Browsers: Chrome: 84.0.4147.105 Firefox: 80.0 npmPackages: gatsby: ^2.23.12 => 2.24.53 gatsby-background-image: ^1.1.1 => 1.1.2 gatsby-image: ^2.4.15 => 2.4.16 gatsby-plugin-google-analytics: ^2.3.13 => 2.3.13 gatsby-plugin-layout: ^1.3.10 => 1.3.10 gatsby-plugin-manifest: ^2.4.21 => 2.4.27 gatsby-plugin-module-resolver: ^1.0.3 => 1.0.3 gatsby-plugin-offline: ^3.2.21 => 3.2.26 gatsby-plugin-react-helmet: ^3.3.10 => 3.3.10 gatsby-plugin-react-svg: ^3.0.0 => 3.0.0 gatsby-plugin-sharp: 2.6.26 => 2.6.26 gatsby-source-filesystem: ^2.3.24 => 2.3.27 gatsby-source-graphql: ^2.7.1 => 2.7.2 gatsby-transformer-sharp: ^2.5.13 => 2.5.14
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 19
- Comments: 47 (14 by maintainers)
Commits related to this issue
- :ambulance: Images from Gatsby not generating Error from Gatsby generate images https://github.com/gatsbyjs/gatsby/issues/26723 not working, so delete the quality and leave it as standard — committed to danestves/danestves.com-cloudflare-pages by danestves 4 years ago
- Add gatsby-source-wordpress-experimental, Fix error on building process by updating gatsby-plugin-sharp (https://github.com/gatsbyjs/gatsby/issues/26723\#issuecomment-683891919) — committed to shoxton/codevux-website by shoxton 4 years ago
My current solution is to downgrade gatsby-plugin-sharp to version 2.6.26.
NOTE: this was a preliminary post as I was chasing the problem with my system. Eventually I realized by instrumenting and running the pngquant binary manually that everything was working. It turns out that the imagemin-pngquant has special handling to look for exit code “99”. Unfortunately, the way to access this change from
error.code
toerror.exitCode
.When I forced the verbose option and added some logging in the (mentioned below) index.js routine, I realized that “error.code” was returning EPIPE (means connection no longer there) or undefined. Since it always worked (regardless of quality parameter) when I ran pngquant manually from command line, I assumed there was a problem with the invocation of the binary through execa.
BTW the package in question is at https://github.com/imagemin/imagemin-pngquant The underlying binary is at https://pngquant.org/ In the notes on binary, you will see the standard (for this package) practice of returning exit code 99 whenever the output ends up being the same as the input due to characteristics of the input image and the requested quality parameter. The imagemin-pngquant routine was trying to catch this. But, we need to make a change to the reference as shown below.
Here is the patch that seems to work. Using package imagemin-pngquant with version 9.0.0, look at index.js Change this code (literally just
error.code
toerror.exitCode
):To this:
I will leave some of the details here for others to verify… Chasing some issues in which the pngquant invocation returns an error code that in index.js shows as “undefined” (should be 99) so the imagemin-pngquant routine will realize it is ok to skip the particular attempt…running the binary manually always gets a 99. When this code happens, the input is returned as output (ie no change). So, the question is why does an error code of undefined appear sometimes?
I have been seeing the same issues since recent updates of sharp-related libraries. After convincing myself there were no cache issues, I then homed in on failing PNG handling. Then I thought it was transparent PNG only. In the end, I think there are timing issues in how long the executable runs before the subprocess exits. Finally, I realized the code in imagemin-pngquant was checking the wrong element (error.code). Once I changed to
error.exitCode
, everything worked.For reference, here is my environment (using v9.0.0 of imagemin-pngquant), from gatsby info:
And a quick check shows pngquant itself is version 2.10.1 on my machine (pulled from the packages under
node_modules/pngquant-bin
)I’ll sort out a pull request once I am sure there are no negative effects - doing the above at least allowed things to build and images to process.
BTW, this is the detailed “error” that results when running the pngquant binary manually (an error code 99):
Note - on that “error” above, pngquant is just saying “I can’t do this so use the input as output”. From command line, the return code is 99. Eventually I sorted this out as mentioned above.
When I have the quality argument set to 100 I get the error, once I changed quality to a number like 90 it works again.
after so long time I found this bug issue…
On this place they closed. https://github.com/gatsbyjs/gatsby/issues/21515
Looks like
imagemin-pngquant
changed from v6 to v9Looks like the error is swallowed so here is the real error:
Command failed with exit code 99: ccc\\node_modules\\pngquant-bin\\vendor\\pngquant.exe - --strip --quality 100-100
failed for me in 2 projects already. Just deleted node_modules and yarn lock, then install and boom… fails
(spent a few solid hours figuring out what’s the problem, between deleting node_modules…etc)
Downgrading I’m getting this error
Gatsby-plugin-sharp wasn't setup correctly in gatsby-config.js. Make sure you add it to the plugins array.
- if fixed by making sure in yarn lock there is no reference to the new version ofGatsby-plugin-sharp
I just wanted to confirm that I am having the same error since updating all my dependencies today.
Thank you @davet42, your solution works every time (whilst upgrading and downgrading gatsby-plugin-sharp to any version makes no difference)! While waiting for your pull request to be merged I resolved hacked my build process in Dockerfile (before running
gatsby build
) ensuring the same code as your pull request in imagemin-pngquant:Hopefully someone will find it useful
I faced the same issue after upgrading
gatsby-plugin-sharp
from2.6.2
-->2.6.31
. Then downgraded to2.6.30
but didn’t resolve the issue. I did the following just to resolve it for now but not sure it’s the right way to do itI started to get this error with the most recent version 2.6.31. Downgrading to 2.6.30 fixed the problem for now. I also have my quality setting as 100, although haven’t tried reducing that to fix the issue on the most recent version.
So far this is the only thing that works for me. Thank you @t2ca .
Can you try with
yarn add gatsby-plugin-sharp@png-revert --registry=https://registry.wardpeet.dev
I met the same problem. I solved it through upgrade
gatsby
andgatsby-transformer-sharp
bothThanks @theinhtut , your solution works.
thanks @theinhtut your solution worked for me.
No but I’ve just update the machine that I use to have a more powerful one, works perfectly now
I’ve tried, the update works great on my side, on local and Netlify 🎉
Workaround with latest versions of plugins (without changing the quality)
patch-package
(npm install patch-package
oryarn add patch-package postinstall-postinstall
)"postinstall": "patch-package"
toscripts
inpackage.json
node_modules/imagemin-pngquant/index.js
and changeerror.code
toerror.exitCode
on line 66 (see diff below)npx patch-package imagemin-pngquant
This will save the change that you make to the
index.js
file and apply it any time / anywhere thatnpm install
oryarn
is run in the project.Diff (difference before and after)
Downgrading isn’t resolving this issue for me either
Are there any known workarounds yet? Right now as described previously not even downgrading fixes the issue anymore.