Last active
March 15, 2018 23:08
-
-
Save up209d/bcf58dbd091c8903bc1c82ccb56cc83c to your computer and use it in GitHub Desktop.
Nodejs Require Hacking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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