nodejs/node · warning

Unable to remove old dat file: %s

Error message

Unable to remove old dat file: %s

What it means

In common mode, before renaming the freshly written .dat into the target location, pkgdata removes any pre-existing target file. If remove() returns non-zero it prints the target path and returns that result code. The new file was written successfully; only the replace-in-place step failed.

Source

Thrown at deps/icu-small/source/tools/pkgdata/pkgdata.cpp:636

          fprintf(stdout, "# Writing package file %s ..\n", datFileNamePath);
        }
        result = writePackageDatFile(datFileNamePath, o->comment, o->srcDir, o->fileListFiles->str, nullptr, U_CHARSET_FAMILY ? 'e' :  U_IS_BIG_ENDIAN ? 'b' : 'l');
        if (result != 0) {
            fprintf(stderr,"Error writing package dat file.\n");
            return result;
        }

        if (IN_COMMON_MODE(mode)) {
            char targetFileNamePath[LARGE_BUFFER_MAX_SIZE] = "";

            uprv_strcpy(targetFileNamePath, targetDir);
            uprv_strcat(targetFileNamePath, datFileName);

            /* Move the dat file created to the target directory. */
            if (uprv_strcmp(datFileNamePath, targetFileNamePath) != 0) {
                if (T_FileStream_file_exists(targetFileNamePath)) {
                    if ((result = remove(targetFileNamePath)) != 0) {
                        fprintf(stderr, "Unable to remove old dat file: %s\n",
                                targetFileNamePath);
                        return result;
                    }
                }

                result = rename(datFileNamePath, targetFileNamePath);

                if (o->verbose) {
                    fprintf(stdout, "# Moving package file to %s ..\n",
                            targetFileNamePath);
                }
                if (result != 0) {
                    fprintf(
                            stderr,
                            "Unable to move dat file (%s) to target location (%s).\n",
                            datFileNamePath, targetFileNamePath);
                    return result;
                }

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Delete the stale target .dat manually before rebuilding.
  2. Close any process holding the file (IDE, antivirus, file manager).
  3. Check that the target directory permits delete by the build user.
Defensive patterns

Strategy: validation

Validate before calling

# bash: pre-clean a writable target so remove() won't be needed mid-run
if [ -e "$TARGET_DAT" ] && [ ! -w "$TARGET_DAT" ]; then
  echo "target not removable: $TARGET_DAT" >&2; exit 2
fi
rm -f "$TARGET_DAT" 2>/dev/null || true

Try / catch

# if replace-in-place fails, clean up and retry once
pkgdata "$@" || { rm -f "$TARGET_DAT" && pkgdata "$@"; exit $?; }

Prevention

When it happens

Trigger: The target .dat exists but is read-only, held open by another process, or the directory does not permit deletion.

Common situations: Previous build artifact locked by an IDE/antivirus; restrictive permissions on the target dir; NFS stale file handles.

Related errors


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