nodejs/node · warning

Unable to open directory: %s\n

Error message

Unable to open directory: %s\n

What it means

In isFileModTimeLater, opendir(checkAgainst) returned nullptr so the directory could not be enumerated. The function prints the path and returns false, meaning the target is treated as out-of-date (a rebuild will be forced). The most common errno causes are ENOENT (not found), EACCES (permission), and ENOTDIR (a file, not a directory).

Source

Thrown at deps/icu-small/source/tools/toolutil/filetools.cpp:89

                        /* If this new path is a directory, make a recursive call with the newpath. */
                        closedir(subDirp);
                        isLatest = isFileModTimeLater(filePath, newpath.data(), isDir);
                        if (!isLatest) {
                            break;
                        }
                    } else {
                        int32_t latest = whichFileModTimeIsLater(filePath, newpath.data());
                        if (latest < 0 || latest == 2) {
                            isLatest = false;
                            break;
                        }
                    }

                }
            }
            closedir(pDir);
        } else {
            fprintf(stderr, "Unable to open directory: %s\n", checkAgainst);
            return false;
        }
#endif
    } else {
        if (T_FileStream_file_exists(checkAgainst)) {
            int32_t latest = whichFileModTimeIsLater(filePath, checkAgainst);
            if (latest < 0 || latest == 2) {
                isLatest = false;
            }
        } else {
            isLatest = false;
        }
    }

    return isLatest;
}

/* Compares the mod time of both files returning a number indicating which one is later. -1 if error ocurs. */

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Verify the directory exists and is searchable: ls -ld <path>.
  2. Correct permissions (chmod +rx) so the build user can read and traverse it.
  3. Ensure the argument is a directory, not a file.
  4. Recreate the expected directory if it was deleted by a prior clean step.

Example fix

# before: directory missing or not readable
opendir('/build/dep') -> NULL

# after: ensure dir exists and is readable
mkdir -p /build/dep && chmod +rx /build/dep
Defensive patterns

Strategy: validation

Validate before calling

// Verify checkAgainst is an existing, searchable directory before isFileModTimeLater.
#include <sys/stat.h>
#include <unistd.h>
bool isSearchableDir(const char *p) {
    struct stat st;
    return stat(p, &st) == 0 && S_ISDIR(st.st_mode) && access(p, R_OK | X_OK) == 0;
}

Prevention

When it happens

Trigger: checkAgainst does not exist, is not a directory, or is not readable/searchable by the build user; the directory was removed between a stat and the opendir.

Common situations: Stale dependency directories referenced after a clean; permission stripping by packaging; passing a file path where a directory was expected; NFS mount not yet ready.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/3a30d0e4f7b43c53. Report an issue: GitHub.