Skip to content

Not runable on Node.js v16 #131

Open
Open

Description

@fisker

Step to reproduce

  1. Compile

    npm run compile
    
  2. Edit dist/index.js to make it runable on Node.js v16

    Replace

    import isBinaryPath from "is-binary-path";
    

    with

    const isBinaryPath = () => false;
    
  3. Test

    node dist/bin package.json -c
    

I got

[Error: ENOENT: no such file or directory, scandir '<...>\prettier-cli\undefined'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '<...>\\prettier-cli\\undefined'
}

@43081j Maybe caused by #116, mind take a look?

Activity

  1. added theissue type on Nov 6, 2026
  2. 43081j commented on Nov 6, 2026

    @43081j
    Collaborator

    @fisker this is because we use dirent.parentPath which doesn't exist in Node 16.x.

    if we want to keep 16.x support (we should since its presumably a breaking change to drop it), we will need @fabiospampinato to emit the full path in tiny-readdir's onDirents.

    i can open a PR there

  3. fisker commented on Nov 6, 2026

    @fisker
    MemberAuthor

    If that's the case, we can fix ig in bundle step to use dirent.parentPath ?? dirent.path. I'll have a test when I back to laptop.

  4. 43081j commented on Nov 6, 2026

    @43081j
    Collaborator

    no we can't.

    a dirent has name and, in newer Node, parentPath. the name is the basename, the parentPath is path to the parent directory.

    the solution is for tiny-readdir to emit the path of the directory it is reading, so we can join(dir, name). that is the equivalent of what works in newer node via parentPath.

    here's the readdir PR: fabiospampinato/tiny-readdir#5
    i also have the prettier-cli branch ready once that gets released.

  5. fisker commented on Nov 6, 2026

    @fisker
    MemberAuthor

    no we can't.

    I don't understand, parentPath is equivalent of the old Dirent#path, it should work.

    https://nodejs.org/api/deprecations.html#dep0178-direntpath

  6. 43081j commented on Nov 6, 2026

    @43081j
    Collaborator

    i suppose the docs are misleading.

    16.x doesn't have path or parentPath.

    import {readdirSync} from "fs";
    
    const [dirent] = readdirSync('.', { withFileTypes: true });
    
    console.log(
      process.version,
      "path:",
      typeof dirent.path,
      "parentPath:",
      typeof dirent.parentPath
    );

    v16.20.2 path: undefined parentPath: undefined
    v26.2.0 path: undefined parentPath: string
    v18.20.8 path: string parentPath: string

    the solution is tiny-readdir passing the root path to us

  7. fisker commented on Nov 8, 2026

    @fisker
    MemberAuthor

    You are right, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions