diff --git a/lib/fs_utils/generate.js b/lib/fs_utils/generate.js
index <HASH>..<HASH> 100644
--- a/lib/fs_utils/generate.js
+++ b/lib/fs_utils/generate.js
@@ -192,12 +192,15 @@ const generate = (path, sourceFiles, config, optimizers) => {
       return Promise.reject(error);
     })
     .then(data => {
-      common.writeFile(path, data.code);
-      return data;
+      return common.writeFile(path, data.code).then(() => {
+        return data;
+      });
     })
     .then(data => {
       if (withMaps) {
-        common.writeFile(mapPath, data.map.toString());
+        return common.writeFile(mapPath, data.map.toString()).then(() => {
+          return data;
+        });
       }
       return data;
     });
We have to return the 'write' promise, else the callbacks are called before the files are actually written