Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Command failed with EPIPE #363

Open
quanghn96 opened this issue Jul 4, 2020 · 10 comments
Open

Error: Command failed with EPIPE #363

quanghn96 opened this issue Jul 4, 2020 · 10 comments

Comments

@quanghn96
Copy link

I have install imagemin-mozjpeg and when I optimize jgp image, I get this issue.

Error: Command failed with EPIPE: /usr/local/lib/node_modules/imagemin-mozjpeg/node_modules/mozjpeg/vendor/cjpeg
write EPIPE


    at afterWriteDispatched (internal/stream_base_commons.js:78:25)
    at writeGeneric (internal/stream_base_commons.js:73:3)
    at Socket._writeGeneric (net.js:714:5)
    at Socket._write (net.js:726:8)
    at doWrite (_stream_writable.js:415:12)
    at writeOrBuffer (_stream_writable.js:399:5)
    at Socket.Writable.write (_stream_writable.js:299:11)
    at Socket.Writable.end (_stream_writable.js:584:10)
    at Socket.end (net.js:545:31)
    at handleInput (/usr/local/lib/node_modules/imagemin-mozjpeg/node_modules/execa/lib/stream.js:17:17)

@Antonyrahul
Copy link

I am also getting the same error in ubuntu 20.4 . Working fine on windows

@dudeful
Copy link

dudeful commented Dec 21, 2020

I just had a similar issue yesterday, on AWS Lambda. In case someone is also facing it, and the development environment is Windows, then I believe this is the solution for you. (note that here in my example I'm using Serverless Framework for building and deploying, however, the principle should work regardless of the use of Serverless)

I tried a few different solutions, but the easiest and fastest solution was to install the Windows Subsystem for Linux and run Serverless Deploy from the Ubuntu terminal on windows.

The issue is that some packages are OS-dependent, meaning that the same package installed on different OSs are going to produce different installations. Therefore your locally build/run works fine because you installed the packages on Windows environment and you are running the packages code on Windows environment, however, when you deploy to AWS it is now running on Amazon Linux and your packages that are OS-dependant (like mozjpeg, jpegtran, etc) are going to fail during the run. So your best shot is to just install the packages, build and deploy your project from a Linux environment (not sure if all Linux distros fit in this statement, but Ubuntu certainly does).

Here's the timeline for what I did:

  1. Install and enable the WSL with Ubuntu (no big deal at all, 10min top, just follow Microsofts doc)
  2. Open the Ubuntu terminal as an administrator (if you don't run as administrator it won't allow you to properly run "npm install" in the next steps)
  3. Make sure everything is updated, just run "apt install upgrade"
  4. Create a folder by running "mkdir your-folder-name" (or just cd directly into your project's original folder, you can do it by Shift+RightClick on the given folder and choosing "Open Linux Shell Here". I preferred to separate it to avoid messing with my original stuff)
  5. Get into the newly created folder by running "cd your-folder-name"
  6. Clone your repository into that folder or just copy/paste it manually (to open your current folder from Ubuntu terminal on Windows just run "explorer.exe .")
  7. Run the good and old "npm install" from the Ubuntu terminal
  8. Now here's a pitfall, if you have your AWS KEYS/SECRETS on your .env file, and you set your serverless.yml file to use the environment variables from the .env file, the next step will fail if you don't have the .env file in place (and you will only see the real error on CloudWatch because the console logged error in the browser will be a CORS error)
  9. Run "Serverless Deploy" to deploy your project

That's it.
Took me around 20min to perform this solution while the others, even though some being effective (like CodeBuild), were more confusing therefore more time-consuming.

@Antonyrahul
Copy link

Hello @dudeful
I was able to pinpoint the error to a ubuntu package named libpng12-0. Mozjpeg uses this package as a dependency . So installing it will fis this error. But i am running a ubuntu 20.04 and libping 12 is not available for ubuntu versions greater that 16.04. So i had to manually install it and it woked fine after that.
I have raised an issue with the package moderators to provide support for new versions of libping. After that it should be fine.

@dudeful
Copy link

dudeful commented Dec 21, 2020

@Antonyrahul Glad to here that you found an even easier solution! I'm just confused that you were installing, building and deploying you project from an Ubuntu 20.04 environment and you still got this error. Makes me think that we are facing slightly different issues here, since I was able to fix it after just changing my environment to Ubuntu 20.04. Am I getting this right?

After facing this issue with OS-dependent packages I started to think about moving to linux for good, since I'm relying 100% on AWS Amazon Linux for running my code.
Do you know other issues that I could prevent, in this context, by having my local development environment running on Linux?

Btw, thanks for open an issue with the package moderators for a more solid fix.

@Antonyrahul
Copy link

Hello @dudeful
Yes i am facing issues in ubuntu 20.4 . I have both windows 10 OS and ubuntu 20.4 OS . The package was working fine in windows 10 . I am facing issues only in ubuntu 20.4 . I was facing problems with both mozjpeg and pngquant packages. My requirement was to compress vendor uploaded images from say 20mb to 1mb irrespective of the format (to store in the server). I found that converting them to webp format works great than jpeg or png compression algorithms and was able to acheive the required solution. And yeah for my requirement the images need not be in the same format the vendor has uploaded.It just has to be of a smaller size so that it loads faster to the end user. So that solution was perfect for me. You can find the webp conversion package here https://www.npmjs.com/package/webp-converter
Thank you

@dudeful
Copy link

dudeful commented Dec 22, 2020

Hi @Antonyrahul, thanks for sharing! I wasn't aware of such improvements when using webp compression. I have the same requirements that you mentioned, so I'm probably going with your solution as well.

@gnitnuj
Copy link

gnitnuj commented Feb 6, 2021

Try checking your memory and/or timeout settings for your Lambda. I was able to resolve the intermittent EPIPE errors I was seeing after increasing both. It is likely due to insufficient memory, but I'm mentioning both just in case. Also for reference I was running Node 12 & I had the ImageMagick layer.

@lucasbeatdapp
Copy link

Has there been any developments with this? I'm running into the same issue with trying to compress images with imagemin-mozjpeg in an ubuntu 20.04 environment and haven't been able to find a solution

@mbforbes
Copy link

I'm running into the same error on macOS.

It happens every time with some images, and never with others. When it fails, nothing is written to the output file.

Example run:

$ imagemin IMG_4034.jpeg --plugin.mozjpeg.quality=80 > IMG_4034.jpg
Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:98:16)
    
$ ll | grep 4034
-rw-r--r--@  1 max  staff   1.2M Jul 26 22:20 IMG_4034.jpeg
-rw-r--r--   1 max  staff     0B Jul 26 22:41 IMG_4034.jpg

If an imagemin developer is interested, I'm happy to provide an example photo that reproduces this.

@joepagan
Copy link

joepagan commented Jul 28, 2022

Just chipping in with how I resolved this issue on debian 11 bullseye (on M1 mac):

FROM --platform=linux/amd64 node:14

COPY ./docker/development/run-node.sh /

RUN apt-get update && apt-get install -y \
    autoconf \
    make \
    libjpeg-progs \
    libpng-dev \
    multiarch-support \
&& \
    wget -O /tmp/libpng12-0.deb http://ftp.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_amd64.deb \
&& \
    apt install /tmp/libpng12-0.deb \
&& \
    chmod +x /run-node.sh

CMD /run-node.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants