A file disappears after changing if I use "brunch watch" #1303

Closed
r-zzi opened this Issue Apr 19, 2016 · 9 comments

Projects

None yet

3 participants

@r-zzi
Contributor
r-zzi commented Apr 19, 2016

Description

I'm a beginner in Elixir/Phoenix/Brunch and probably I'm doing something wrong here, but I've got a strange behaviour of Brunch.

Steps:

  1. I create a new project using Phoenix framework: mix phoenix.new.
  2. It contains web/static/js/app.js and web/static/js/socket.js files by default.
  3. When I open Chrome Inspector I can see both files (from source maps) and combined app.js, containing content of both files.
  4. I change socket.js in any manner, for example by adding a new line.
  5. Brunch watcher detects the change and recompiles sources.
  6. I refresh the page and now I can see only app.js (from sm) and combined app.js, not containing the content of socket.js. I also manually check priv/static/js/app.js and it reflects the same.

So, the socket.js file disappeared and will appear only after restarting brunch watch or executing brunch build.

Also I tested it with another file: I created test.js and then changed it. It dissapeared from the combined file. As I see, this always affects exactly the file that I'm changing.
Sometimes it doesn't happen after the first change, but after 2nd or 3rd.

In order to capture logs, I disabled the Brunch watcher in the Phoenix config and run it manually. Also I updated it to the latest version.

Environment

  1. Brunch: 2.6.6
  2. Node: 5.10.1
  3. NPM: 3.8.3
  4. Operating system: Ubuntu 15.10

package.json contents

{
  "repository": {
  },
  "dependencies": {
    "babel-brunch": ">=6.0.0",
    "brunch": ">=2.6.6",
    "clean-css-brunch": ">=1.8.0",
    "css-brunch": ">=1.7.0",
    "javascript-brunch": ">=1.8.0",
    "uglify-js-brunch": ">=1.7.0",
    "phoenix": "file:deps/phoenix",
    "phoenix_html": "file:deps/phoenix_html"
  }
}

brunch config contents

exports.config = {
  files: {
    javascripts: {
      joinTo: "js/app.js"
    },
    stylesheets: {
      joinTo: "css/app.css"
    },
    templates: {
      joinTo: "js/app.js"
    }
  },

  conventions: {
    assets: /^(web\/static\/assets)/
  },

  paths: {
    watched: [
      "web/static",
      "test/static"
    ],

    public: "priv/static"
  },

  plugins: {
    babel: {
      ignore: [/web\/static\/vendor/]
    }
  },

  modules: {
    autoRequire: {
      "js/app.js": ["web/static/js/app"]
    }
  },

  npm: {
    enabled: true,
    whitelist: ["phoenix", "phoenix_html"]
  }
};

Other useful files, when present (bower.json etc.)

Logs of watch -d

  • I've been changing only socket.js several times:
$ node_modules/brunch/bin/brunch watch -d
  brunch:config Trying to load brunch-config +0ms
  brunch:plugins Loaded plugins: babel-brunch, css-brunch, javascript-brunch +457ms
  brunch:watch add package.json +19ms
  brunch:watch add brunch-config.js +0ms
  brunch:watch add web/static/assets/favicon.ico +14ms
  brunch:asset Init web/static/assets/favicon.ico directory=web/static/assets/ destPath=priv/static/favicon.ico rel=favicon.ico +1ms
  brunch:watch add web/static/assets/robots.txt +2ms
  brunch:asset Init web/static/assets/robots.txt directory=web/static/assets/ destPath=priv/static/robots.txt rel=robots.txt +0ms
  brunch:watch add web/static/css/app.css +1ms
  brunch:list Reading web/static/css/app.css +0ms
  brunch:watch add web/static/js/app.js +0ms
  brunch:list Reading web/static/js/app.js +1ms
  brunch:watch add web/static/js/socket.js +0ms
  brunch:list Reading web/static/js/socket.js +0ms
  brunch:asset Copied web/static/assets/favicon.ico +7ms
  brunch:asset Copied web/static/assets/robots.txt +1ms
  brunch:file Init web/static/css/app.css: isntModule=false isWrapped=false +1ms
  brunch:pipeline Compiling web/static/css/app.css @ CSSCompiler +2ms
  brunch:list Compiled web/static/css/app.css +2ms
  brunch:file Init web/static/js/app.js: isntModule=false isWrapped=true +0ms
  brunch:pipeline Compiling web/static/js/app.js @ BabelCompiler +1ms
  brunch:pipeline Compiling web/static/js/app.js @ JavaScriptCompiler +168ms
  brunch:file Init web/static/js/socket.js: isntModule=false isWrapped=true +18ms
  brunch:pipeline Compiling web/static/js/socket.js @ BabelCompiler +0ms
  brunch:pipeline Compiling web/static/js/socket.js @ JavaScriptCompiler +101ms
  brunch:watch add web/static/assets/images/phoenix.png +32ms
  brunch:asset Init web/static/assets/images/phoenix.png directory=web/static/assets/ destPath=priv/static/images/phoenix.png rel=images/phoenix.png +0ms
  brunch:asset Copied web/static/assets/images/phoenix.png +15ms
  brunch:list Reading node_modules/phoenix_html/priv/static/phoenix_html.js +58ms
  brunch:modules Wrapping web/static/js/app.js @ commonjs +9ms
  brunch:file Generated source map for 'web/static/js/app.js'  +1ms
  brunch:list Compiled web/static/js/app.js +6ms
  brunch:list Reading node_modules/phoenix/priv/static/phoenix.js +2ms
  brunch:modules Wrapping web/static/js/socket.js @ commonjs +32ms
  brunch:file Generated source map for 'web/static/js/socket.js'  +1ms
  brunch:list Compiled web/static/js/socket.js +29ms
  brunch:file Init node_modules/phoenix_html/priv/static/phoenix_html.js: isntModule=true isWrapped=true +0ms
  brunch:file Init node_modules/phoenix/priv/static/phoenix.js: isntModule=true isWrapped=true +0ms
  brunch:modules Not wrapping (is vendor file) node_modules/phoenix_html/priv/static/phoenix_html.js +70ms
  brunch:list Compiled node_modules/phoenix_html/priv/static/phoenix_html.js +2ms
  brunch:modules Not wrapping (is vendor file) node_modules/phoenix/priv/static/phoenix.js +181ms
  brunch:list Compiled node_modules/phoenix/priv/static/phoenix.js +7ms
  brunch:write Writing 2/2 files +79ms
  brunch:generate Concatenating [node_modules/phoenix/priv/static/phoenix.js, node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js] => priv/static/js/app.js +27ms
  brunch:generate Concatenating [web/static/css/app.css] => priv/static/css/app.css +50ms
  brunch:generate Writing priv/static/js/app.js +11ms
  brunch:generate Writing priv/static/css/app.css +1ms
  brunch:generate Writing priv/static/js/app.js.map +9ms
  brunch:generate Writing priv/static/css/app.css.map +10ms
19 Apr 19:08:45 - info: compiled 5 files into 2 files, copied 3 in 1.8 sec
  brunch:watch change web/static/js/socket.js +46s
  brunch:list Reading web/static/js/socket.js +0ms
  brunch:pipeline Compiling web/static/js/socket.js @ BabelCompiler +1ms
  brunch:pipeline Compiling web/static/js/socket.js @ JavaScriptCompiler +3ms
  brunch:modules Wrapping web/static/js/socket.js @ commonjs +10ms
  brunch:file Generated source map for 'web/static/js/socket.js'  +4ms
  brunch:list Compiled web/static/js/socket.js +0ms
  brunch:write Writing 1/2 files +67ms
  brunch:file Disposing node_modules/phoenix/priv/static/phoenix.js +0ms
  brunch:generate Concatenating [node_modules/phoenix/priv/static/phoenix.js, node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js] => priv/static/js/app.js +1ms
  brunch:generate Writing priv/static/js/app.js +8ms
  brunch:generate Writing priv/static/js/app.js.map +54ms
19 Apr 19:09:32 - info: compiled socket.js and 3 cached files into app.js in 155ms
  brunch:watch change web/static/js/socket.js +26s
  brunch:list Reading web/static/js/socket.js +0ms
  brunch:pipeline Compiling web/static/js/socket.js @ BabelCompiler +2ms
  brunch:pipeline Compiling web/static/js/socket.js @ JavaScriptCompiler +3ms
  brunch:modules Wrapping web/static/js/socket.js @ commonjs +2ms
  brunch:file Generated source map for 'web/static/js/socket.js'  +0ms
  brunch:list Compiled web/static/js/socket.js +0ms
  brunch:write Writing 1/2 files +67ms
  brunch:generate Concatenating [node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js] => priv/static/js/app.js +0ms
  brunch:generate Writing priv/static/js/app.js +3ms
  brunch:generate Writing priv/static/js/app.js.map +33ms
19 Apr 19:09:58 - info: compiled socket.js and 2 cached files into app.js in 118ms
  brunch:watch change web/static/js/socket.js +16s
  brunch:list Reading web/static/js/socket.js +0ms
  brunch:pipeline Compiling web/static/js/socket.js @ BabelCompiler +1ms
  brunch:pipeline Compiling web/static/js/socket.js @ JavaScriptCompiler +17ms
  brunch:modules Wrapping web/static/js/socket.js @ commonjs +1ms
  brunch:file Generated source map for 'web/static/js/socket.js'  +0ms
  brunch:list Compiled web/static/js/socket.js +0ms
  brunch:write Writing 1/2 files +67ms
  brunch:generate Concatenating [node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js] => priv/static/js/app.js +0ms
  brunch:generate Writing priv/static/js/app.js +2ms
  brunch:generate Writing priv/static/js/app.js.map +23ms
19 Apr 19:10:14 - info: compiled socket.js and 2 cached files into app.js in 129ms
  • I changed test.js and then socket.js:
$ node_modules/brunch/bin/brunch watch -d
  brunch:speed Created BrunchWatcher 250ms +0ms
  brunch:application Trying to load brunch-config +3ms
  brunch:speed Loaded config 274ms +20ms
  brunch:speed Loading plugins 274ms +0ms
  brunch:speed Loaded plugin babel-brunch 498ms +224ms
  brunch:speed Loaded plugin clean-css-brunch 574ms +76ms
  brunch:speed Loaded plugin css-brunch 575ms +1ms
  brunch:speed Loaded plugin javascript-brunch 607ms +32ms
  brunch:speed Loaded plugin uglify-js-brunch 683ms +76ms
  brunch:plugins Loaded plugins: babel-brunch, css-brunch, javascript-brunch +2ms
  brunch:speed Loaded plugins 685ms +0ms
  brunch:speed Loaded watcher 686ms +1ms
  brunch:watch add package.json +23ms
  brunch:watch add brunch-config.js +9ms
  brunch:watch add /home/czi/Elixir/brunchdemo/brunchdemo/node_modules/phoenix/priv/static/phoenix.js +1ms
  brunch:list Reading node_modules/phoenix/priv/static/phoenix.js +1ms
  brunch:speed Starting compilation 720ms +0ms
  brunch:watch add /home/czi/Elixir/brunchdemo/brunchdemo/node_modules/phoenix_html/priv/static/phoenix_html.js +0ms
  brunch:list Reading node_modules/phoenix_html/priv/static/phoenix_html.js +1ms
  brunch:file Init node_modules/phoenix/priv/static/phoenix.js: isntModule=true isWrapped=true +4ms
  brunch:file Init node_modules/phoenix_html/priv/static/phoenix_html.js: isntModule=true isWrapped=true +4ms
  brunch:modules Not wrapping (is vendor file) node_modules/phoenix/priv/static/phoenix +4ms
  brunch:list Compiled node_modules/phoenix/priv/static/phoenix.js +7ms
  brunch:modules Not wrapping (is vendor file) node_modules/phoenix_html/priv/static/phoenix_html +0ms
  brunch:list Compiled node_modules/phoenix_html/priv/static/phoenix_html.js +0ms
  brunch:watch add web/static/assets/favicon.ico +10ms
  brunch:asset Init web/static/assets/favicon.ico directory=web/static/assets/ relativePath=favicon.ico destinationPath=priv/static/favicon.ico +2ms
  brunch:watch add web/static/assets/robots.txt +1ms
  brunch:asset Init web/static/assets/robots.txt directory=web/static/assets/ relativePath=robots.txt destinationPath=priv/static/robots.txt +1ms
  brunch:watch add web/static/css/app.css +1ms
  brunch:list Reading web/static/css/app.css +0ms
  brunch:watch add web/static/js/app.js +0ms
  brunch:list Reading web/static/js/app.js +0ms
  brunch:watch add web/static/js/socket.js +1ms
  brunch:list Reading web/static/js/socket.js +0ms
  brunch:watch add web/static/js/test.js +10ms
  brunch:list Reading web/static/js/test.js +0ms
  brunch:asset Copied web/static/assets/favicon.ico +14ms
  brunch:asset Copied web/static/assets/robots.txt +1ms
  brunch:file Init web/static/css/app.css: isntModule=false isWrapped=false +0ms
  brunch:pipeline Compiling web/static/css/app.css @ CSSCompiler +1ms
  brunch:list Compiled web/static/css/app.css +1ms
  brunch:file Init web/static/js/app.js: isntModule=false isWrapped=true +1ms
  brunch:pipeline Compiling web/static/js/app.js @ BabelCompiler +0ms
  brunch:pipeline Compiling web/static/js/app.js @ JavaScriptCompiler +165ms
  brunch:modules Wrapping web/static/js/app @ commonjs +9ms
  brunch:file Generated source map for 'web/static/js/app.js'  +0ms
  brunch:list Compiled web/static/js/app.js +6ms
  brunch:file Init web/static/js/socket.js: isntModule=false isWrapped=true +0ms
  brunch:pipeline Compiling web/static/js/socket.js @ BabelCompiler +1ms
  brunch:pipeline Compiling web/static/js/socket.js @ JavaScriptCompiler +72ms
  brunch:modules Wrapping web/static/js/socket @ commonjs +3ms
  brunch:file Generated source map for 'web/static/js/socket.js'  +1ms
  brunch:list Compiled web/static/js/socket.js +3ms
  brunch:file Init web/static/js/test.js: isntModule=false isWrapped=true +0ms
  brunch:pipeline Compiling web/static/js/test.js @ BabelCompiler +0ms
  brunch:pipeline Compiling web/static/js/test.js @ JavaScriptCompiler +3ms
  brunch:modules Wrapping web/static/js/test @ commonjs +3ms
  brunch:file Generated source map for 'web/static/js/test.js'  +0ms
  brunch:list Compiled web/static/js/test.js +1ms
  brunch:watch add web/static/assets/images/phoenix.png +2ms
  brunch:asset Init web/static/assets/images/phoenix.png directory=web/static/assets/ relativePath=images/phoenix.png destinationPath=priv/static/images/phoenix.png +0ms
  brunch:speed Watcher is ready 1053ms +1ms
  brunch:asset Copied web/static/assets/images/phoenix.png +26ms
  brunch:write Writing 2/2 files +70ms
  brunch:generate Concatenating [node_modules/phoenix/priv/static/phoenix.js, node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js, web/static/js/test.js] => priv/static/js/app.js +9ms
  brunch:common Writing priv/static/js/app.js +120ms
  brunch:common Writing priv/static/js/app.js.map +25ms
  brunch:generate Concatenating [web/static/css/app.css] => priv/static/css/app.css +16ms
  brunch:common Writing priv/static/css/app.css +13ms
  brunch:common Writing priv/static/css/app.css.map +5ms
19 Apr 12:51:11 - info: compiled 6 files into 2 files, copied 3 in 1.1 sec
  brunch:watch change web/static/js/test.js +26s
  brunch:list Reading web/static/js/test.js +3ms
  brunch:pipeline Compiling web/static/js/test.js @ BabelCompiler +2ms
  brunch:pipeline Compiling web/static/js/test.js @ JavaScriptCompiler +15ms
  brunch:modules Wrapping web/static/js/test @ commonjs +1ms
  brunch:file Generated source map for 'web/static/js/test.js'  +0ms
  brunch:list Compiled web/static/js/test.js +1ms
  brunch:write Writing 1/2 files +66ms
  brunch:generate Concatenating [node_modules/phoenix/priv/static/phoenix.js, node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js, web/static/js/test.js] => priv/static/js/app.js +1ms
  brunch:common Writing priv/static/js/app.js +23ms
  brunch:common Writing priv/static/js/app.js.map +49ms
19 Apr 12:51:38 - info: compiled test.js and 4 cached files into app.js in 164ms
  brunch:watch change web/static/js/test.js +11s
  brunch:list Reading web/static/js/test.js +0ms
  brunch:pipeline Compiling web/static/js/test.js @ BabelCompiler +1ms
  brunch:pipeline Compiling web/static/js/test.js @ JavaScriptCompiler +15ms
  brunch:modules Wrapping web/static/js/test @ commonjs +0ms
  brunch:file Generated source map for 'web/static/js/test.js'  +0ms
  brunch:list Compiled web/static/js/test.js +1ms
  brunch:write Writing 1/2 files +66ms
  brunch:generate Concatenating [node_modules/phoenix/priv/static/phoenix.js, node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js, web/static/js/test.js] => priv/static/js/app.js +1ms
  brunch:common Writing priv/static/js/app.js +13ms
  brunch:common Writing priv/static/js/app.js.map +61ms
19 Apr 12:51:49 - info: compiled test.js and 4 cached files into app.js in 161ms
  brunch:watch change web/static/js/socket.js +17s
  brunch:list Reading web/static/js/socket.js +0ms
  brunch:pipeline Compiling web/static/js/socket.js @ BabelCompiler +5ms
  brunch:pipeline Compiling web/static/js/socket.js @ JavaScriptCompiler +53ms
  brunch:modules Wrapping web/static/js/socket @ commonjs +3ms
  brunch:file Generated source map for 'web/static/js/socket.js'  +1ms
  brunch:list Compiled web/static/js/socket.js +2ms
  brunch:write Writing 1/2 files +66ms
  brunch:generate Concatenating [node_modules/phoenix/priv/static/phoenix.js, node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js, web/static/js/test.js] => priv/static/js/app.js +2ms
  brunch:common Writing priv/static/js/app.js +7ms
  brunch:common Writing priv/static/js/app.js.map +31ms
19 Apr 12:52:07 - info: compiled socket.js and 4 cached files into app.js in 182ms
  brunch:watch change web/static/js/socket.js +8s
  brunch:list Reading web/static/js/socket.js +2ms
  brunch:pipeline Compiling web/static/js/socket.js @ BabelCompiler +1ms
  brunch:pipeline Compiling web/static/js/socket.js @ JavaScriptCompiler +14ms
  brunch:modules Wrapping web/static/js/socket @ commonjs +1ms
  brunch:file Generated source map for 'web/static/js/socket.js'  +0ms
  brunch:list Compiled web/static/js/socket.js +0ms
  brunch:write Writing 1/2 files +66ms
  brunch:generate Concatenating [node_modules/phoenix/priv/static/phoenix.js, node_modules/phoenix_html/priv/static/phoenix_html.js, web/static/js/app.js, web/static/js/socket.js, web/static/js/test.js] => priv/static/js/app.js +2ms
  brunch:common Writing priv/static/js/app.js +8ms
  brunch:common Writing priv/static/js/app.js.map +33ms
19 Apr 12:52:15 - info: compiled socket.js and 4 cached files into app.js in 153ms
@r-zzi r-zzi changed the title from A file disappeared after changing if I use "brunch watch" to A file disappears after changing if I use "brunch watch" Apr 19, 2016
@r-zzi
Contributor
r-zzi commented Apr 19, 2016

http://recordit.co/pO1T0s1sSm A screencast showing the problem:

  1. I launch brunch watch d.
  2. Show that the content of the combined app.js file contains the content of socket.js at the end.
  3. I change socket.js.
  4. Show that the content of app.js doesn't contain the required part anymore.
@goshakkk
Member

This could be related to the editor you are using, writing file in some way so that it first is emptied and saved, then the contents added a ms after... #1250 — some users of sublime and brackets reported that already.

For sublime, tweaking the atomic_save settings seemed to do the trick.

@r-zzi
Contributor
r-zzi commented Apr 20, 2016

Thanks, I'm using Sublime 3.
I set "atomic_save": true and now it works correctly.

@r-zzi
Contributor
r-zzi commented Apr 23, 2016 edited

I also would like to add that I'm trying other editors, looking for the best one for Elixir and I got exactly the same issue with Emacs.

@r-zzi
Contributor
r-zzi commented Apr 23, 2016 edited

I added

watcher: {
    awaitWriteFinish: true,
    usePolling: true
}

to the Brunch config, as I read in another issue, and it seems it helped.

@goshakkk
Member

Yeah... does seem to be happening due to the way some editors handle file saves. Never once had a problem like this with my old and trusted vim :)

We probably should put this into docs or something? Also maybe there is some way to handle write-specific cases like this on the chokidar side... though I'm not completely sure. cc @paulmillr @es128

As far as this issue is concerned, I guess it's been resolved @r-zzi?

@r-zzi
Contributor
r-zzi commented May 10, 2016

If there is no any possible solutions better than polling, yes, it's resolved :)

@paulmillr paulmillr closed this May 10, 2016
@paulmillr
Member

@goshakkk could you put it into the docs?

@goshakkk
Member

@paulmillr sure — #1361

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