@@ -327,20 +327,24 @@ export async function findNodeApiModulePaths(
327327 const result : string [ ] = [ ] ;
328328 const pendingResults : Promise < string [ ] > [ ] = [ ] ;
329329
330- for await ( const dirent of await fs . promises . opendir ( candidatePath ) ) {
331- if (
332- dirent . isFile ( ) &&
333- dirent . name === MAGIC_FILENAME &&
334- hasPlatformExtension ( platform , candidatePath )
335- ) {
336- result . push ( candidatePath ) ;
337- } else if ( dirent . isDirectory ( ) ) {
338- // Traverse into the child directory
339- // Pushing result into a list instead of awaiting immediately to parallelize the search
340- pendingResults . push (
341- findNodeApiModulePaths ( options , path . join ( suffix , dirent . name ) )
342- ) ;
330+ try {
331+ for await ( const dirent of await fs . promises . opendir ( candidatePath ) ) {
332+ if (
333+ dirent . isFile ( ) &&
334+ dirent . name === MAGIC_FILENAME &&
335+ hasPlatformExtension ( platform , candidatePath )
336+ ) {
337+ result . push ( candidatePath ) ;
338+ } else if ( dirent . isDirectory ( ) ) {
339+ // Traverse into the child directory
340+ // Pushing result into a list instead of awaiting immediately to parallelize the search
341+ pendingResults . push (
342+ findNodeApiModulePaths ( options , path . join ( suffix , dirent . name ) )
343+ ) ;
344+ }
343345 }
346+ } catch {
347+ // Intentionally left empty: if the directory cannot be read, we skip it
344348 }
345349 const childResults = await Promise . all ( pendingResults ) ;
346350 result . push ( ...childResults . flatMap ( ( filePath ) => filePath ) ) ;
0 commit comments