imagemin-mozjpeg icon indicating copy to clipboard operation
imagemin-mozjpeg copied to clipboard

Some images throw "write EPIPE" error

Open laoshu133 opened this issue 6 years ago • 7 comments

This may not be a bug in the imagemin-mozjpeg, but I'm not sure it's a bug in Node.js, so I'm going to make an issue here; I made a simple demo to reproduce this bug, it is an error on stdin, but the spawn of exitcode is right.

DEMO: https://repl.it/@laoshu133/spawnpipe

image

laoshu133 avatar Jun 01 '18 09:06 laoshu133

try this solution:

https://github.com/imagemin/imagemin-mozjpeg/issues/28#issuecomment-397825824

BenzLeung avatar Jun 16 '18 17:06 BenzLeung

Thanks for reply, but [email protected] doesn't work.

image

laoshu133 avatar Jun 18 '18 14:06 laoshu133

Downgrading to version 6 does not work for me too. Some interesting observations -

  1. The EPIPE error only occurs for me in AWS elastic beanstalk. Locally build works fine.
  2. Still trying to understand if it happens for certain images or all.

image

bhuvanmehra avatar May 18 '20 07:05 bhuvanmehra

@laoshu133 Did u find the solution to this? I am experimenting the same issue.

frossi85 avatar May 30 '20 22:05 frossi85

I'm using gridsome which uses this library. I get this error on GitHub Actions, but not when building locally.

darrenmothersele avatar Jul 17 '20 10:07 darrenmothersele

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.

dudeful avatar Dec 21 '20 09:12 dudeful

After hours of research and experimenting with different settings, I managed to resolve mozjpeg errors when using Linux/Docker. The issue is particularly when using alpine image.

My updated Dockerfile:

FROM node:12-buster-slim

RUN npm i npm@latest -g

WORKDIR /usr/src

COPY ./app/package*.json ./

RUN apt-get update && apt-get install -y --no-install-recommends \
    autoconf \
    automake \
    g++ \
    libpng-dev \
    make\
    nasm \
    -y wget \
    && wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
    && dpkg -i /tmp/libpng12.deb \
    && rm /tmp/libpng12.deb \
    && npm install --no-optional && npm cache clean --force \
    npm install -g gulp \
    && npm install gulp

ENV PATH /usr/src/node_modules/.bin/:$PATH

WORKDIR /usr/src/app

COPY . .

These settings might save you hours of frustration. BTW Node's alpine image is NOT recommended because of long build time, even though it's small image size.

Happy coding!

xshapira avatar Aug 26 '21 05:08 xshapira