Fs.writefile not writing to github repo on build from netlify

Hi! so I wanted to use netlify cms for one of my projects and I am a netlify newbie. so my collections export in JSON format extension: JSON , format: JSON and obviously netlify cms create a file, and each entry to the file is stored as independent JSON files so I wanted to combine all this json files into one json file on the build . Now the problem I am facing is on build in the local server there is no problem the code combines all JSON files into a new JSON file but when building on netlify the file is not created in the git repo ad no error is also thrown.

folder structure:-


var fs = require("fs");
var path = require("path");
let jsonfile = []; 
const dirPath = path.join(__dirname, "../products")
fs.readdir(dirPath, (err, fileNames) => {
fileNames.forEach(filename => {
    const filePath = path.join(dirPath,"/",filename)
    let jsonData = require(filePath);
 fs.writeFile("./src/Shared/products/products.json", JSON.stringify(jsonfile), err => { 
    // Checking for errors 
   if (err) throw err;  
   console.log("Done writing"); // Success 


"build": "node ./public/main.js && react-scripts build",
Well, this works perfectly in the local server but on build in netlify there are no errors thrown yet the file is not created.
well I am also open any ideas where I can get a combined JSON file directly from the CMS (I have aleady tried list but it looks a bit messsy .)

Hi there,

Are you aware that we have NO git permissions to push to your git provider? I don’t think you’re asking for this in your post, but your title implies you are trying to write back to your git provider during build which you can do, but you need to do more work to include auth details as mentioned here:

Reading your post, I think I see the problem:


Are you aware that our build environment is case sensitive? Do you actually have a “Shared” folder (with capital S) in git? I suspect is lowercase and in our build environment Shared != shared, so perhaps you’re ending up with both or the wrong one?

This article may be helpful to change the case in git so you can try to fix it: