imagemin / imagemin-gifsicle

Imagemin plugin for Gifsicle
MIT License
116 stars 55 forks source link

regression in `6.0.0` #27

Closed alexander-akait closed 6 years ago

alexander-akait commented 6 years ago

Code:

"use strict";

const fs = require("fs");
const path = require("path");
const imagemin = require("imagemin");
const imageminGifsicle = require("imagemin-gifsicle");

Promise.resolve()
  .then(() => {
    // Works good with `.gif` and `.png`, but doesn't work with `.js`, `.css` and other extension what unknown in `file-type`
    const buffer = fs.readFileSync(path.join(__dirname, "__tests__/fixtures/loader.js"));

    return imagemin
      .buffer(buffer, {
        plugins: [imageminGifsicle()]
      })
      .then(result => {
        console.log("Original size:" + buffer.length);
        console.log("Compressed size:" + result.length);
      });
  })
  .catch(error => {
    throw error;
  });

throw TypeError: Cannot read property 'ext' of null.

It is happens when you send as buffer non binary file. Loaders/plugins using imagemin for webpack are broken in some cases.

/cc @1000ch

brothatru commented 6 years ago

Seeing the same error.

Here's my stacktrace:

(node:31268) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'ext' of null
    at module.exports.input (/node_modules/is-gif/index.js:4:42)
    at buf (/node_modules/imagemin-gifsicle/index.js:13:7)
    at fsP.readFile.then.data (/node_modules/imagemin/index.js:20:60)
    at <anonymous>
(node:31268) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:31268) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.