denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.1k stars 5.36k forks source link

ReferenceError: EISDIR is not defined | node pollyfill is missing a constant #23695

Closed bowtiedgnome closed 5 months ago

bowtiedgnome commented 5 months ago

Version: Deno 1.42.4

The following code is resulting in an error

      if (isDirectory && !options.recursive) {
        throw new ERR_FS_EISDIR({
          code: "EISDIR",
          message: "is a directory",
          path,
          syscall: "rm",
          errno: EISDIR,
        });
      }

see: https://github.com/denoland/deno/blob/main/ext/node/polyfills/internal/fs/utils.mjs

Most likely the linked code needs to be updated to:

      if (isDirectory && !options.recursive) {
        throw new ERR_FS_EISDIR({
          code: "EISDIR",
          message: "is a directory",
          path,
          syscall: "rm",
          errno: osConstants.errno.EISDIR,
        });
      }

The error that I see.

error: ReferenceError: EISDIR is not defined
    return fs.rmSync(path,  { ...options });
              ^
    at __node_internal_ (ext:deno_node/internal/fs/utils.mjs:894:18)
    at Object.rmSync (ext:deno_node/_fs/_fs_rm.ts:27:13)
    at removeSync (file:///{redacted}/gnomejs/fs/node/mod.ts:494:15)
    at file:///{redacted}/gnomejs/fs/move_node_test.ts:246:3

(I can work around it by setting options.force, however, this seems like a bug).

marvinhagemeister commented 5 months ago

For completeness: These are the steps to reproduce the error.

  1. Create a file main.ts with these contents:

    import fs from "node:fs";
    import * as path from "node:path";
    
    const dir = path.join(import.meta.dirname!, "foo");
    fs.rmSync(dir);
  2. Create an empty folder foo next to main.ts
  3. Run deno run -A main.ts