0

I'm running the following code in my node.js project. I've required "imagemin" and "imageminGifsicle". I've getting the following error

}).then(files => { ^ TypeError: imagemin(...).then is not a function

Do I have not used promises in my projects before. Do I need to include them to use .then ?

imagemin(['export/sample/out.gif'], 'export/sample/out2.gif', {
 plugins: [
  imageminGifsicle({optimizationLevel: 1})
 ]
}).then(files => {
  console.log(files);
  console.log("finished");
}).catch(err => {
  console.log("ERR:"+err);
  throw err;
});
Rob
  • 14,746
  • 28
  • 47
  • 65
Jason Small
  • 1,064
  • 1
  • 13
  • 29
  • How did you install imagemin? It has a dependency on "promise.pipe" and should support the .then chaining based on its docs. – Eric N Oct 15 '16 at 14:03

2 Answers2

3

.then is Promise related and imagemin added this only on 5.0.0.

What version of it are you using?

Felipe Sabino
  • 17,825
  • 6
  • 78
  • 112
0

Well, yes- you can choose the library you prefer for promises, and use "then" function with promises. In this case you are using imagemin:

const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
const imageminPngquant = require('imagemin-pngquant');

imagemin on GitHub

For using Promises, you can read some of the specifications and info on MDN and here on stackoverflow

Chen
  • 2,958
  • 5
  • 26
  • 45