scionoftech / webp-converter

[DEPRECATED] A small node.js library for converting any image to webp file format or converting webp image to any image file format.
MIT License
229 stars 43 forks source link

Convert cwebp error in 2.1.1 #3

Closed sicter closed 7 years ago

sicter commented 7 years ago
/node_modules/webp-converter/webpconverter.js:43
            callback(error);//return error
            ^

TypeError: callback is not a function
    at /node_modules/webp-converter/webpconverter.js:43:5
    at ChildProcess.exithandler (child_process.js:209:5)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:90:13)
    at Socket.emit (events.js:182:7)
    at Pipe._onclose (net.js:484:12)

My code is the following:

const converter = require('webp-converter');
const save_webp = (imagePath, cacheTime) => {
    return new Promise((resolve, reject) => {
        converter.cwebp(imagePath, imgDestination, "80", (status) => {
            //if conversion successfull status will be 'converted successfully' 
            if (status == 'converted successfully') {
                database.store(imgDestination, cacheTime);
                resolve(imgDestination);
            } else {
                reject(imageConvertError);
            }
        });
    });
}

This code is never able to complete as the app crashes with the error above before the status check. I have since reverted to v2.0.1, which I originally used and it now works, but I do not know specifically what would have caused the error

scionoftech commented 7 years ago

In your code, you need to define status as a callback function. TRY THIS. const converter = require('webp-converter'); const save_webp = (imagePath, cacheTime) => { return new Promise((resolve, reject) => { converter.cwebp(imagePath, imgDestination, "80", function(status) => { //if conversion successfull status will be 'converted successfully' if (status == 'converted successfully') { database.store(imgDestination, cacheTime); resolve(imgDestination); } else { reject(imageConvertError); } }); }); }

sicter commented 7 years ago

(status) => {...} is correct syntax in es6 for a function where status is the parameter, which nodejs supports, and it definitely works with v2.0.1.

function(status) => {...} is invalid js syntax However I did try:

function(status) {...}

which also failed on v2.1.1 but works on v2.0.1. I did not test any versions in between and I am fine with sticking to 2.0.x since I don't need gif conversion. Just wanted to bring up something I saw. Thanks for the quick response