Whenever I try to use png-js in Node.js, I get this strange error:
/home/anderson/node_modules/png-js/png-node.js:152
b1 = this.data[this.pos++] << 24;
^
TypeError: Cannot read property '8' of undefined
at PNG.readUInt32 (/home/anderson/node_modules/png-js/png-node.js:152:21)
at new PNG (/home/anderson/node_modules/png-js/png-node.js:56:26)
at /home/anderson/node_modules/png-js/png-node.js:34:15
at [object Object].<anonymous> (fs.js:88:5)
at [object Object].emit (events.js:67:17)
at Object.oncomplete (fs.js:1059:12)
Here's the program that produced this output:
var PNG = require('png-js');
PNG.decode('some.png', function(pixels) {
// pixels is a 1d array of decoded pixel data
});
In the past, I've been able to use the png-js module without any trouble. Is it possible that this module might conflict with another node.js module that I've installed?
In this particular case, the error message appeared because a file named some.png
did not exist in the same folder as the node.js script.