Jason Small
Jason Small

Reputation: 1054

then is not a function

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;
});

Upvotes: 0

Views: 1849

Answers (2)

Chen
Chen

Reputation: 3060

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

Upvotes: 0

Felipe Sabino
Felipe Sabino

Reputation: 18225

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

What version of it are you using?

Upvotes: 3

Related Questions