NodeJS Photoshop PSD parser toJSON() has no method

1.4k views Asked by At

Im using https://github.com/meltingice/psd.js to parse a PSD file in node,

I see that toJSON() can be used, https://github.com/won21kr/psd.js-1

but when I try to use on a simple hello world after installing the module,

npm install psd

toJSON() gives me error:

info = psd.toJSON(); ^ TypeError: Object # has no method 'toJSON'

normal log works fine,

var PSD = require('psd');
var psd = PSD.fromFile("AntoineVeglas_Filter_BW.psd");
psd.parse();

node = psd.tree().descendants()[0];
console.log(node);

info = psd.toJSON();

how to parse to valid json my psd tree object? cheers

2

There are 2 answers

0
mostruash On BEST ANSWER

You are aware that toJSON function is in a fork project of the original right? So if you install psd using npm, you will get the original project which has no toJSON function.

You should checkout the fork (won21kr) and either put it in your node_modules folder, or put it somewhere else and access the js file with a relative module path notation: require('./psd-fork/index.js').

0
Владимир Лукьянчиков On

change psd.tree().descendants()[0]; to psd.tree().descendants()[0].export();