png-js:无法读取未定义的属性'8'

时间:2012-10-01 19:21:15

标签: node.js

每当我尝试在Node.js中使用png-js时,我都会遇到这个奇怪的错误:

/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)

以下是产生此输出的程序:

var PNG = require('png-js');
PNG.decode('some.png', function(pixels) {
    // pixels is a 1d array of decoded pixel data
});

过去,我已经能够毫无困难地使用png-js模块了。该模块是否可能与我安装的另一个node.js模块冲突?

1 个答案:

答案 0 :(得分:2)

在这种特殊情况下,出现错误消息是因为名为some.png的文件与node.js脚本不在同一文件夹中。