Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browserify should not create empty output files on error #899

Closed
mietek opened this issue Sep 13, 2014 · 5 comments · Fixed by #1673
Closed

Browserify should not create empty output files on error #899

mietek opened this issue Sep 13, 2014 · 5 comments · Fixed by #1673

Comments

@mietek
Copy link

mietek commented Sep 13, 2014

When an error occurs, Browserify 5.11.2 creates an empty output file. This should not happen, as it messes up make-based workflows.

$ cat >foo.js <<EOF
var quux = require('quux');
EOF

$ browserify foo.js -o bar.js
Error: Cannot find module 'quux' from '/private/tmp/foo'
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:50:17
    at process (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:119:43)
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:128:21
    at load (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:60:43)
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:66:22
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:21:47
    at Object.oncomplete (fs.js:107:15)

$ ls -l | grep bar.js
-rw-r--r--  1 mietek  wheel   0 13 Sep 14:53 bar.js
@asadovsky
Copy link

+1, this behavior is quite annoying.

@rla
Copy link

rla commented Oct 20, 2014

+1, as a workaround, those who use GNU make, just add .DELETE_ON_ERROR as a target https://www.gnu.org/software/make/manual/html_node/Special-Targets.html

kika added a commit to rackmaze/node-browserify that referenced this issue May 2, 2015
@kika
Copy link

kika commented May 2, 2015

I'm offering a PR for this
#1239

kika added a commit to rackmaze/node-browserify that referenced this issue May 2, 2015
@natevw
Copy link
Contributor

natevw commented Jan 6, 2017

Looks like the proposed fix for this wasn't a great solution. Seems to me the proper way to handle this would be:

  1. Create a temporary file
  2. Output the work to this file
  3. When/if successful, move the temporary file to the actual path

This is ± how e.g. Cocoa does atomic file overwrites [in that case the temporary and target files need to be on same volume, doesn't seem quite as important here just to fix this issue so long as you avoid/handle the EXDEV error that rename(2) would give e.g. by writing the temporary file in the same place as the actual destination but with a unique suffix].

natevw added a commit to natevw/node-browserify that referenced this issue Jan 6, 2017
Write browserify command output to a temporary file, overwriting the target file atomically upon success (and simply cleaning up the tempfile on error).

This has two benefits:

* user won't be left with an empty file if compilation fails (which can break toolchains that rely on destination files/timestamps to indicate build status, Make or django-pipeline for just two examples)
* output file can never end up in a half-written state during even a successful compilation
@natevw
Copy link
Contributor

natevw commented Jan 6, 2017

(Alternate pull request submitted.)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

5 participants