gulp-imagemin: ERROR getting "optipng ENOENT" in ttf2woff2

Hi all! I am using gulp-imageming for almost a year now. Recently after running npm install to update all modules I am getting and ENOENT error strangely in ttf2woff2 plugin. I have no idea how is this plugin connected to gulp-images or optipng.

Do you have any ideas what to try? Thank you.

I am runnigng this: gulpImagemin({ optimizationLevel: 4, svgoPlugins: [ {removeViewBox: false} ] })

I am getting this error:

/XY/node_modules/ttf2woff2/jssrc/ttf2woff2.js:1
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["re
Error: spawn /XY/node_modules/optipng-bin/vendor/optipng ENOENT
    at exports._errnoException (util.js:856:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at nextTickCallbackWith2Args (node.js:475:9)
    at process._tickCallback (node.js:389:17)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 15

Commits related to this issue

Most upvoted comments

Hi all, on my case. I have just run manually the post-install script and it magically works node node_modules/optipng-bin/lib/install.js

TL;DR:

Don’t forget to install this package on your system (for me, an alpine linux):

RUN apk --update --no-cache \
		add  \
                automake \
		git \
		alpine-sdk  \
		nasm  \
		autoconf  \
		build-base \
		zlib \
		zlib-dev \
		libpng \
		libpng-dev\
		libwebp \
		libwebp-dev \
		libjpeg-turbo \
		libjpeg-turbo-dev

I test also to install it and I have the error on alpine docker. So steps are:

cd node_modules/jpegtran-bin && node lib/install.js

Many errors appear and indicate that on my system it miss :

RUN apk --update --no-cache \
		add  \
		git \
		alpine-sdk  \
		nasm  \
		autoconf  \
		build-base

Then same thing for optipng

cd node_modules/optipng-bin && node lib/install.js
Starting project_cache-node_1
  ⚠ spawn /path/to/node_modules/optipng-bin/vendor/optipng ENOENT
  ⚠ optipng pre-build test failed
  ℹ compiling from source
  ✖ Error: ./configure --with-system-zlib --prefix="/path/to/node_modules/optipng-bin/vendor" --bindir="/path/to/node_modules/optipng-bin/vendor" && make install
Command failed: ./configure --with-system-zlib --prefix="/path/to/node_modules/optipng-bin/vendor" --bindir="/path/to/node_modules/optipng-bin/vendor"

    at ChildProcess.exithandler (child_process.js:205:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at maybeClose (internal/child_process.js:899:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

It seems it lakes of z-lib so I install it on my alpine image :

apk --update --no-cache \
		add  \
		git \
		alpine-sdk  \
		nasm  \
		autoconf  \
		build-base \
		zlib \
		zlib-dev \
		libpng \
		libpng-dev\
		libwebp \
		libwebp-dev \
		libjpeg-turbo \
		libjpeg-turbo-dev

And then we re-launch the test

node_modules/optipng-bin && node lib/install.js"
Starting project_cache-node_1
  ⚠ spawn /path/to/node_modules/optipng-bin/vendor/optipng ENOENT
  ⚠ optipng pre-build test failed
  ℹ compiling from source
  ✔ optipng built successfully

And for the gif optimisation with gifsicle

node_modules/gifsicle && node lib/install.js
Startingproject_cache-node_1
  ⚠ spawn /path/to/node_modules/gifsicle/vendor/gifsicle ENOENT
  ⚠ gifsicle pre-build test failed
  ℹ compiling from source
  ✖ Error: autoreconf -ivf && ./configure --disable-gifview --disable-gifdiff --prefix="/path/to/node_modules/gifsicle/vendor" --bindir="/path/to/node_modules/gifsicle/vendor" && make install
Command failed: autoreconf -ivf
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal  --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory

    at ChildProcess.exithandler (child_process.js:205:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at maybeClose (internal/child_process.js:899:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

We need to install also automake and then:

node_modules/gifsicle && node lib/install.js
  ⚠ spawn /path/to/node_modules/gifsicle/vendor/gifsicle ENOENT
  ⚠ gifsicle pre-build test failed
  ℹ compiling from source
  ✔ gifsicle built successfully

So, this is the whole installation:

RUN apk --update --no-cache \
		add  \
                automake \
		git \
		alpine-sdk  \
		nasm  \
		autoconf  \
		build-base \
		zlib \
		zlib-dev \
		libpng \
		libpng-dev\
		libwebp \
		libwebp-dev \
		libjpeg-turbo \
		libjpeg-turbo-dev

Finally, to compile and install the binaries correctly after this debug session, I full remove ~/.npm cache and node_modules and i lauch a npm install.

I was running into a similar issue when running in a docker alpine container. What fixed for me was adding gifsicle, jpegtran-bin, optipng-bin, and svgo as dependencies as well:

{
  "devDependencies": {
    "gulp-imagemin": "^3.0.3",
    "gifsicle": "^3.0.4",
    "jpegtran-bin": "^3.2.0",
    "optipng-bin": "^3.1.2",
    "svgo": "^0.7.2"
  }
}

Same problem but with pngquant and zopflipng This workaround should work for all this kind of problems:

node node_modules/pngquant-bin/lib/install.js
node node_modules/zopflipng-bin/lib/install.js
node node_modules/jpegoptim-bin/lib/install.js
node node_modules/optipng-bin/lib/install.js
node node_modules/jpeg-recompress-bin/lib/install.js

@sindresorhus There’s a way to fix this behaviour?

Cool…it is just a question of size. Maybe it works greats with Jessie one. Using many Alpine instead of Jessie could save lots of disk space 😉

I found that installing the following packages on Alpine Linux got things building successfully again:

apk --update --no-cache \
    add \
    alpine-sdk \
    autoconf \
    automake \
    bash \
    build-base \
    git \
    lcms2-dev \
    libjpeg-turbo \
    libjpeg-turbo-dev \
    libpng \
    libpng-dev \
    libwebp \
    libwebp-dev \
    nasm \
    zlib \
    zlib-dev

But in the end I switched from running node on Alipine Linux to using one of the official node docker images (node:8). These are based on Debian Jessie and gave me none of these problems.

All Unix based have to install it, so not bad, I create ASAP a PR for README.

@chadyred I wonder if all of those dependencies should be listed in the readme or wiki?

@ayoubice @sindresorhus Bumped into this again today.

The source of the issue appears to be that the optipng post install script fails to run as it isn’t handling spaces in directory names. Here’s the output on OS X following an npm install optipng

> optipng-bin@3.0.2 postinstall /Volumes/My HD/My Project Dir with SPACES/node_modules/optipng/node_modules/optipng-bin
> node lib/install.js

 ⚠ Command failed: /Volumes/My HD/My Project Dir with SPACES/node_modules/optipng/node_modules/optipng-bin/vendor/optipng --version
/bin/sh: /Volumes/My: Permission denied

After that, the optipng pre-build test fails and ugliness follows.

As suggested, running the post-install script manually completes the install and hey presto. I assume this is because the command is properly escaped when run manually.