Intervox/node-webp

evenst.js 174 error

Closed this issue · 6 comments

When i try to run this code

const fs = require('fs');
const CWebp = require('cwebp').CWebp;

var encoder = new CWebp(fs.readFileSync(file));
  console.log(file);
  console.log(outputFile);
  encoder.toBuffer(function(err, data){
      if (err) {
        console.error(err);
      } else {
        fs.writeFileSync(outputFile, data);
        console.log(file + ' encoded successfully');
      }
  });

I have the following error:

> node ./scripts/generateWebp.js

./src/img/about-video-bg.jpg
./src/img/about-video-bg.webp
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: 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:704:5)
    at Socket._write (net.js:716:8)
    at doWrite (_stream_writable.js:410:12)
    at writeOrBuffer (_stream_writable.js:394:5)
    at Socket.Writable.write (_stream_writable.js:294:11)
    at Socket.Writable.end (_stream_writable.js:579:10)
    at Socket.end (net.js:535:31)
    at CWebp._write (D:\project\node_modules\cwebp\lib\io.js:43:17)
Emitted 'error' event at:
    at onwriteError (_stream_writable.js:425:12)
    at onwrite (_stream_writable.js:456:5)
    at _destroy (internal/streams/destroy.js:40:7)
    at Socket._destroy (net.js:604:3)
    at Socket.destroy (internal/streams/destroy.js:32:8)
    at afterWriteDispatched (internal/stream_base_commons.js:78:17)
    at writeGeneric (internal/stream_base_commons.js:73:3)
    [... lines matching original stack trace ...]
    at doWrite (_stream_writable.js:410:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! youhelp-react@0.1.0 webp: `node ./scripts/generateWebp.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the youhelp-react@0.1.0 webp script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.

Just tested your code with a sample image and it worked fine.

Could you please provide additional information about your environment, including:

  • node.js version: node --version
  • WebP binaries version: cwebp -version
  • cwebp package version: npm ls cwebp

You may also try installing the latest cwebp version following Installation instruction in readme.

Please, pay attention to WebP versions compatibility table. If you're using the latest cwebp package then you need version 0.5.0 or later of WebP binaries.

Node: v10.15.3
cwebp: "cwebp command not exists"
npm cwebp: cwebp@2.0.3

node-webp is a thin wrapper around WebP binaries. So in order for this package to work you need WebP binaries somewhere in your environment.

Judging from your exception I may assume that you have them, but their version is too low for streaming and buffer APIs to work.

Probably you're using webp npm package with WepP 0.3.x.

If my assumption is correct, then you have two ways of solving your problem:

  • Install latest WebP binaries into your system instead of using webp npm package.
  • Use cwebp@0.1.x which is compatible with WepP 0.3.x. cwebp@0.1.x emulates streaming API using temporary files, so it doesn't require any native streaming support from your WebP version. This technique is significantly slower because it rely on your disk for transferring data between cwebp and node.js processes, but it'll work with any WepP version.

Thanks. The problem in webp binaries - i haven't them at all. Found them at https://developers.google.com/speed/webp/download but there are no installer for win64, so as i understand the only way to install them - download compiled version and add path to extracted folder with binaries to a system PATH.

I don't know anything about WebP installer, but pre-compiled win64 binaries are available at WebP downloads repository.

Here is a direct link: libwebp-1.0.3-windows-x64.zip.

You can also use download_webp.ps1 PowerShell script I wrote to setup windows test environment.
It'll download the latest WebP binaries for your system architecture and unpack them into your system32 directory.

Thank you, this is what I need.