title: ENOENT: no such file or directory writing file with fs
body: <p>I am not sure where I went wrong to get this error:</p>
  
  <pre><code>{ Error: ENOENT: no such file or directory, open '../dist/index.html'
      at Error (native)
    errno: -2,
    code: 'ENOENT',
    syscall: 'open',
    path: '../dist/index.html' }
  </code></pre>
  
  <p>I put a <code>console.log("Build HTML error")</code> in my code to see if the error fires and it does. I also used <code>console.log($.html());</code> to see if the correct HTML is generated and it is. </p>
  
  <p>my code:</p>
  
  <pre><code>fs.readFile(__dirname + '/../app/index.html', 'utf8', (err, markup) =&gt; {
      if (err) {
          console.log("grab HTML error");
          return console.log(err);
      }
  
      const $ = cheerio.load(markup);
  
      console.log($.html());
      $('head').prepend('&lt;link rel="stylesheet" href="styles.css"&gt;');
  
      fs.writeFile('../dist/index.html', $.html(), 'utf8', err =&gt; {
         if (err) {
             console.log("Build HTML error");
             return console.log(err);
         }
         console.log('index.html written to /dist'.green);
      });
  });
  </code></pre>
  
  <p>As you can see, I have the <code>dist</code> directory in the correct place and the other files generated from <code>webpack</code> are generated and built</p>
  
  <p>Project structure:</p>
  
  <p><a href="https://i.stack.imgur.com/gc4E0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gc4E0.png" alt="enter image description here"></a></p>