Q:

ENOENT on writeFileSync works on repl fails on gulp-asset-manifest

I'm using the code on this site to write a gulp file for a Windows aspnet + angularjs app.
I'm running only styles for now, and when I run gulp I get:
Error: ENOENT, no such file or directory 'C:\project\build\manifest-debug.json'
at Error (native)
at Object.fs.openSync (fs.js:502:18)
at Object.fs.writeFileSync (fs.js:1103:15)
at writeManifestFile (C:\project\node_modules\gulp-asset-manifest\index.js:30:8)
at resetManifestFile (C:\project\node_modules\gulp-asset-manifest\index.js:51:5)
at module.exports (C:\project\node_modules\gulp-asset-manifest\index.js:76:5)
at getManifest (C:\project\Gulpfile.js:97:12)
at Gulp.<anonymous> (C:\project\Gulpfile.js:126:15)
at module.exports (C:\project\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\project\node_modules\gulp\node_modules\orchestrator\index.js:273:3)

Looking at C:\project\node_modules\gulp-asset-manifest\index.js:30:8 I see:
fs.writeFileSync(filename, JSON.stringify(data));

So I ran this on node's REPL:
fs.writeFileSync('C:\\project\\build\\manifest-debug.json', 'hi');

And the file was created correctly.
I tried running gulp again with an existing file and got the exact same error.
I added a console.log(filename); before line 30 on index.js and I got:
./build/manifest-debug.json

So I ran fs.writeFileSync('./build/manifest-debug.json', 'hi'); on REPL from the same folder and it worked too.
Not sure what's going on. 
I'm running everything with UAC disabled and on a command prompt with admin rights.

A:

The problem was fs.writeFileSync requires the path to exist.
At the point gulp-asset-manifest was called ./build was nonexistent, because the clean task deleted the entire path.

