diff --git a/lib/deps.js b/lib/deps.js index 81fa996a..7dfc1203 100644 --- a/lib/deps.js +++ b/lib/deps.js @@ -54,8 +54,18 @@ const loadModule = (name) => { const subKeys = Object.keys(pkg.exports).map((key) => key.substring(2)); const subNames = subKeys.filter(validSubmodules); for (const subName of subNames) { - const sub = appRequire(name + '/' + subName); - lib[subName] = sub; + try { + const sub = appRequire(name + '/' + subName); + if (lib[subName] && lib[subName] === sub[subName]) continue; + lib[subName] = sub; + } catch (err) { + if (err.code === 'MODULE_NOT_FOUND' && pkg.peerDependenciesMeta) { + const moduleName = metautil.between(err.message, "'", "'"); + const optional = pkg.peerDependenciesMeta[moduleName]?.optional; + if (optional) continue; + } + throw err; + } } return lib; };