Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,25 @@ function findExternalLibraries(
paths: [projectRoot],
});
} catch (e) {
// require.resolve fails if the dependency is a local node module.
if (
// require.resolve fails if the `./package.json` subpath is not explicitly defined in the library's `exports` field in its package.json
'code' in e &&
e.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
) {
// find the closest library's package.json with the search paths
for (const nodeModulesPath of require.main.paths) {
const packageJsonFilePath = path.join(
nodeModulesPath,
dependency,
'package.json',
);
if (fs.existsSync(packageJsonFilePath)) {
configFilePath = packageJsonFilePath;
break;
}
}
} else if (
// require.resolve fails if the dependency is a local node module.
dependencies[dependency].startsWith('.') || // handles relative paths
dependencies[dependency].startsWith('/') // handles absolute paths
) {
Expand All @@ -214,7 +231,9 @@ function findExternalLibraries(
pkgJson.dependencies[dependency],
'package.json',
);
} else {
}

if (!configFilePath) {
return [];
}
}
Expand Down