requireify
requireify copied to clipboard
throw exceptions while requireify a json file
Not quite sure if it's because my misunderstanding, but seems like requrieify doesn't like requireing json
/private/tmp/t/a.json:1
module.exports= var global = (function(){ return this; }).call(null); if(!global.require){ global.require = function require(key){ return global.require[key.replace(/\\/g, '/')]; }; (function(){ var require = global.require; var ret = global.require; Object.defineProperty(global, 'require', { get: function(){ return ret; }, set: function(newRequire){ ret = function(key){ key = key.replace(/\\/g, '/'); if(require[key]){ return require[key]; }else if(require[key + '/index']){ return require[key + '/index']; }else{ var temp = ret; var module; ret = newRequire; try { module = newRequire(key); } catch(e){ ret = temp; throw e; } ret = temp; return module; } }; for(var key in require){ ret[key] = require[key]; } } }); })(); }{
^
ParseError: Unexpected token var
@huang47 I haven't actually tried this myself with requireing a json file directly. Can you give me an example of the browserified code that you're trying to use?
Thanks.
it's something like below
// in dep.json
{ "hello: "world" }
// in mod.json
var dep = require('./dep.json');
module.exports = function () {
return dep.hello;
};
I have a workaround which prepend "module.exports = " if it's a JSON. From your perspective do you think it's a proper way to address this problem?
@huang47 yes, I do think that this is the correct solution. Any chance you have this fix easily PR-able?
PR #13