UNPKG

whodis-react

Version:

React hooks and components for secure, best practices authentication in seconds

22 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPackageSafely = void 0; const error_fns_1 = require("@ehmpathy/error-fns"); /** * requires a package in a universally safe way * * note: * - carefully prevents react-native's metro bundler from throwing an error while proactively fetching all dependencies * - it specifically requires the import to be within a try-catch to not throw its own error * - ref: https://github.com/react-native-community/discussions-and-proposals/issues/120 */ const getPackageSafely = (packageName) => { try { return require(`${packageName}`); // note: we cast it into a string to avoid: https://stackoverflow.com/questions/42908116/webpack-critical-dependency-the-request-of-a-dependency-is-an-expression } catch (_a) { throw new error_fns_1.HelpfulError('requirePackageSafely.error: package not accessible in this environment', { packageName }); } }; exports.getPackageSafely = getPackageSafely; //# sourceMappingURL=getPackageSafely.js.map