Skip to content

Deno's fs.rmdirSync will incorrectly succeed at removing files #26241

@sbc100

Description

@sbc100

The follow program fails under node and bun:

import fs from 'node:fs';

fs.writeFileSync('foo.txt', 'hello')
fs.rmdirSync('foo.txt')

For exmaple:

$ node test.mjs 
node:fs:1215
  binding.rmdir(pathModule.toNamespacedPath(path));
          ^

Error: ENOTDIR: not a directory, rmdir 'foo.txt'
    at Object.rmdirSync (node:fs:1215:11)
    at file:///usr/local/google/home/sbc/dev/wasm/emscripten/test.mjs:4:4
    at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'rmdir',
  path: 'foo.txt'
}

Node.js v20.19.2

But it succeeds under deno:

$ ~/.deno/bin/deno -A test.mjs
$ stat foo.txt
stat: cannot statx 'foo.txt': No such file or directory

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions