How to require module only if exist. React native
问题 Example: let tmp; try { tmp = require('module-name'); } catch(e) { return; } I get error (react native Metro Bundler): error: bundling failed: Error: Unable to resolve module `module-name` from ... How to require "module-name" only if exist? 回答1: That's what works for me: let myPackage; const myPackageToRequire = 'my-package-to-require'; try { myPackage = require.call(null, myPackageToRequire); } catch (e) {} The variable definition const myPackageToRequire = 'my-package-to-require'; is