diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js index 4da3fe379c4..e217b99fcb0 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js @@ -204,27 +204,8 @@ 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 - // $FlowFixMe[prop-missing] - const paths: Array = require.main.paths; - for (const nodeModulesPath of 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 ) { @@ -233,9 +214,7 @@ function findExternalLibraries( pkgJson.dependencies[dependency], 'package.json', ); - } - - if (!configFilePath) { + } else { return []; } }