Created
August 17, 2021 04:28
-
-
Save christianscott/0d9641ec4a05468ae3b960b5d53322c2 to your computer and use it in GitHub Desktop.
error on import of 3rd party module
This file contains hidden or 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
const mod = require('module'); | |
const os = require('os'); | |
const colors = { | |
red: '\033[0;31m', | |
none: '\033[0m', | |
}; | |
const logErr = (msg) => process.stderr.write(`${colors.red}ERROR: ${msg}${os.EOL}${colors.none}`); | |
mod.prototype.require = new Proxy(mod.prototype.require, { | |
apply(target, self, args){ | |
const [name] = args; | |
if (!mod.builtinModules.includes(name)){ | |
logErr( | |
'cannot require a third-party module from inside this script. ' + | |
'it is run before `yarn install` so can only depend on builtin modules', | |
); | |
process.exit(1); | |
} | |
return Reflect.apply(target, self, args); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment