diff --git a/index.js b/index.js index d04c8e415..e885159b8 100644 --- a/index.js +++ b/index.js @@ -606,7 +606,14 @@ Browserify.prototype._recorder = function (opts) { Browserify.prototype._json = function () { return through.obj(function (row, enc, next) { if (/\.json$/.test(row.file)) { - row.source = 'module.exports=' + sanitize(row.source); + var sanitizedString = sanitize(row.source); + try { + // check json validity + JSON.parse(sanitizedString); + row.source = 'module.exports=' + sanitizedString; + } catch (e) { + this.emit('error', syntaxError(e.message, row.file || row.id)); + } } this.push(row); next(); diff --git a/test/json.js b/test/json.js index a942791c0..64549edeb 100644 --- a/test/json.js +++ b/test/json.js @@ -48,7 +48,6 @@ test('invalid json', function (t) { t.plan(1); b.add(__dirname + '/json/invalid.js'); b.bundle(function (err, src) { - //console.log(src); t.ok(err); }); });