Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Dependencies permanently lost when 0-byte file is read #1585

Closed
jacksonrayhamilton opened this issue Dec 13, 2016 · 1 comment
Closed

Dependencies permanently lost when 0-byte file is read #1585

jacksonrayhamilton opened this issue Dec 13, 2016 · 1 comment

Comments

@jacksonrayhamilton
Copy link
Contributor

Description

I was experiencing an issue when Brunch detected changes to my files. Sometimes, the dependencies of the file that I saved would permanently disappear. Randomly when I would save saved-file.js, which did require('foo'), I would see the error Uncaught Error: Cannot find module 'foo' from 'saved-file.js'. I also saw, in my terminal, that X had decreased from the previous message when compiled saved-file.js and X cached files into app.js in Y ms was printed.

I did a lot of digging into the brunch, deppack and finally fcache source code and found that sometimes fcache was reading 0-byte files. When it would read these empty files, it would still analyze them, and when it found that dependencies of this momentarily-empty file were no longer referenced by any other file, those files would be "unlinked" and not included in the build any more.

This led me back to the Brunch issues, and I found this: #971 and now awaitWriteFinish has solved my problem.

However, I think Brunch probably could have handled 0-byte files more gracefully - in case someone didn't read the docs and find out about awaitWriteFinish (which should maybe even be on by default), or if awaitWriteFinish ever doesn't work (I expect it will eventually fail, since it's timer-based).

Expected behavior

Even after a file is read with 0 bytes and its dependencies are dropped, those dependencies should be re-added if the same file is read again and found to have the same dependencies. If Brunch at least does that, it may be able to recover from reading these 0-byte files, or at least some less knowledgeable users (like I was) wouldn't need to restart their whole server (they could just re-save).

Also, I think that awaitWriteFinish should be in the docs and recommended for various editors, including Emacs.

Actual behavior

When Brunch reads a saving 0-byte file that has dependencies, it stops including those dependencies in the build forever.

Here's a demo: https://github.com/jacksonrayhamilton/brunch-lost-dependencies-demo

Environment

  1. Brunch: 2.9.1
  2. Node: 6.9.2
  3. NPM: 3.10.9
  4. Operating system: Debian GNU/Linux 8

package.json contents

{
  "private": true,
  "scripts": {
    "start": "brunch watch --server"
  },
  "devDependencies": {
    "auto-reload-brunch": "^2.7.1",
    "brunch": "^2.9.1",
    "lodash": "^4.17.2"
  }
}

brunch config contents

/* eslint-env node */

'use strict';

module.exports = {
  files: {
    javascripts: {joinTo: 'app.js'}
  },
  modules: {
    autoRequire: {
      'app.js': ['main']
    }
  }
};
@denysdovhan
Copy link
Contributor

Hi, @jacksonrayhamilton! Thanks for reaching out!

Your issue is related to problems with deppack module.
Here are other issues: deppack related issues.

We're working on it. I believe we will fix that as soon as it possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants