jprichardson / node-jsonfile

Easily read/write JSON files.
MIT License
1.2k stars 321 forks source link

TypeError: Cannot read property 'replace' of undefined #119

Closed SwapnilSoni1999 closed 5 years ago

SwapnilSoni1999 commented 5 years ago

Heres the issue I got while doing

jsonfile.writeFile('./myfile.json', data, (fs.existsSync('./myfile.json')) ? { flag: 'a' } : {}, function(err) { if(err) { console.error("Error while writing config!", err); } else { console.log("Saved!"); } });

Error while writing config! TypeError: Cannot read property 'replace' of undefined at stringify (/home/soni/proj/node/netflix-gen/node_modules/jsonfile/index.js:91:14) at Object.writeFileWithCallback (/home/soni/proj/node/netflix-gen/node_modules/jsonfile/index.js:104:11) at Object.writeFileWithCallback [as writeFile] (/home/soni/proj/node/netflix-gen/node_modules/universalify/index.js:5:67) at main (/home/soni/proj/node/netflix-gen/netflix.js:42:18) at processTicksAndRejections (internal/process/task_queues.js:86:5)

jayellos commented 5 years ago

@SwapnilSoni1999 how did you resolved this error?

SwapnilSoni1999 commented 5 years ago

@jayellos it was issue with my json object

zszep commented 3 years ago

The same here. A quote was missing in my json file