Hafthor
Hafthor

Reputation: 16916

Intermittent browserify bundle failure (probably brfs)

This is an intermittent problem. That is, I can repeat the same build command n times without changing anything and sometimes it will work and sometimes (~30%) it will fail with seemingly no cause. I've been living with this for months now, but it is terribly annoying.

I'm using node (v0.10.35) and browserify (v6.3.4) and brfs (v1.2.0) to bundle some html in my javascript. Intermittently, the build fails with:

events.js:72
        throw er; // Unhandled 'error' event
              ^
SyntaxError: Unterminated string constant (17:4) while parsing file: blah.js
    at raise (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:333:15)
    at readString (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:1073:11)
    at getTokenFromCode (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:854:14)
    at readToken (./httpd/node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:902:15)
    at next (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:1232:5)
    at eat (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:1335:7)
    at expect (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:1360:5)
    at parseExprList (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:2443:9)
    at parseSubscripts (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:2032:24)
    at parseSubscripts (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:2021:14)
    at parseExprSubscripts (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:2012:12)
    at parseMaybeUnary (./node_modules/brfs/node_modules/static-module/node_modules/falafel/node_modules/acorn/acorn.js:1995:16)

It's different line numbers, but each time the build fails, it points to

fs.readFileSync(

I don't think it matters, but I am using gulp v3.8.8. My gulp task is quite simple.

var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
gulp.task('build', function(cb) {
  return browserify(app.src, {
    fullPaths: true,
    transform: ['brfs'],
    debug: true
  }).bundle().pipe(source(app.name)).pipe(gulp.dest(app.dest));
});

Others on this same project with slightly different versions of node and gulp and even different OSes are also experiencing the same problem.

Update: It also fails with just browserify+brfs (most current versions) with the same message. I'm convinced this is a problem with brfs because it doesn't seem to fail if I leave out the transform.

var browserify = require('browserify');
var fs = require('fs');
var b = browserify('blah.js');
b.transform('brfs');
b.bundle().pipe(fs.createWriteStream('out.js'));

Upvotes: 3

Views: 761

Answers (1)

LaurelT
LaurelT

Reputation: 115

I was getting this problem with a similar setup (using reactify to transform, though; it was just giving me "Unterminated string constant" in the error message and didn't specify a js file). Turned out I had a syntax error in a json file (a stray newline inside of a string literal)...

Upvotes: 1

Related Questions