   if mkdirp.sync dirOut
     verbose 3, "mkdir #{dirOut}"
 
-  # Write file
-  fs.writeFileSync fileOut, html
+  # Record
+  deltaTime = process.hrtime(startTime)
+  timeStamp = " (#{deltaTime[0] + Math.round(10000*deltaTime[1]/1000000000)/10000} sec)"
 
   # Clear caches
   cache = null
   hookCache = null
   hookOriginalCache = null
 
-  # Record
-  deltaTime = process.hrtime(startTime)
-  timeStamp = " (#{deltaTime[0] + Math.round(10000*deltaTime[1]/1000000000)/10000} sec)"
-  verbose 1, "compiled #{fileOut}#{timeStamp}", 'cyan'
-  return
+  # Write file
+  fs.writeFile fileOut, html, (err) ->
+
+    if err
+      error "file writing error #{filePath}: #{err}"
+      return
+
+    verbose 1, "compiled #{fileOut}#{timeStamp}", 'cyan'
+    return
 
 # Keep track of which files are watched
 watchCache = {}

      for d in dirs
        watchDir d, dirPath, options

    for f in files

      # Compile and watch all pages
      if isOJPage f
        compileFile f, dirPath, options

      # Watch files that aren't pages
      else if options.watch
        watchFile f, dirPath, options

# nodeModulePaths: Determine node_module paths from a given path
# Implementation is from node.js' Module._nodeModulePaths


# compileFile
# ------------------------------------------------------------------------------
compileFile = (filePath, includeDir, options = {}, cb = ->) ->
  # Time this method
  startTime = process.hrtime()

