Skip to content

Instantly share code, notes, and snippets.

@up209d
Last active March 15, 2018 23:08
Show Gist options
  • Save up209d/bcf58dbd091c8903bc1c82ccb56cc83c to your computer and use it in GitHub Desktop.
Save up209d/bcf58dbd091c8903bc1c82ccb56cc83c to your computer and use it in GitHub Desktop.
Nodejs Require Hacking
let Module = require('module');
let _require = Module.prototype.require;
Module.prototype.require = function() {
let currentPath = arguments[0];
try {
return _require.apply(this,arguments);
} catch (err) {
// Any errors from importing such as
// (not a js module, path cannot be resolved, unsupported extensions)
return currentPath; // fallback to return as a pure string
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment