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 tolerates require() of invalid JSON #1580

Closed
s100 opened this issue Jun 23, 2016 · 3 comments · Fixed by #1700
Closed

Browserify tolerates require() of invalid JSON #1580

s100 opened this issue Jun 23, 2016 · 3 comments · Fixed by #1700
Labels

Comments

@s100
Copy link

s100 commented Jun 23, 2016

This is browserify@13.0.1 and Node.js v6.2.2.

file.json:

{
  key: "value"
}

index.js:

require("./file.json");

Command line:

browserify index.js

Expected output: some kind of error because of the invalid JSON?

Actual output:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports={
  key: "value"
}

},{}],2:[function(require,module,exports){
require("./file.json");
},{"./file.json":1}]},{},[2]);
@jmm
Copy link
Collaborator

jmm commented Jun 23, 2016

Hello @s100, thanks for the report! I agree, that is uncool. We could solve this by trying to parse as JSON at bundling time in the json phase of the pipeline, or defer it to runtime, or if necessary provide an option to toggle. Would you be interested in working on a failing test and / or PR for this?

@s100
Copy link
Author

s100 commented Jun 24, 2016

Unfortunately I don't know the first thing about Browserify's internals, I am just a humble user.

@jmm
Copy link
Collaborator

jmm commented Jun 24, 2016

Ok, no problem, just wanted to give you the first crack at it 😃

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

Successfully merging a pull request may close this issue.

2 participants