Skip to content

Node on Windows can't access filenames containg emojis #49042

@dandrei

Description

@dandrei

Version

v20.5.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

fs

What steps will reproduce the bug?

Create an empty directory and have two files there:

  • TEST 🤖.txt
  • test.js, with the following content:
const path = require("path")
const fs = require("fs");
const {promisify} = require("util");
const access = promisify(fs.access)
const readdir = promisify(fs.readdir)

async function file_exists(f) {
    try {
        await access(f)
        return true;
    } catch (e) {
        console.error(e);
        return false;
    }
}

async function test() {
    for (const f of await readdir('.')) {
        console.log(f, await file_exists(f));
    }
}

test().then()

How often does it reproduce? Is there a required condition?

It happens whenever trying to access a filename contains emoji characters.

What is the expected behavior? Why is that the expected behavior?

All node functions should be able to access these files, especially since readdir correctly lists them, including those containg emojis.

What do you see instead?

The output on Windows is (I've anonymized local system file paths):

Error: ENOENT: no such file or directory, access
    at access (node:fs:236:11)
    at node:internal/util:411:7
    at new Promise (<anonymous>)
    at access (node:internal/util:397:12)
    at file_exists (test.js:9:15)
    at test (test.js:19:30) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'access'
}
TEST 🤖.txt false
test.js true

On Linux and node v16.14.2 it outputs correctly (the output of file_exists is true):

TEST 🤖.txt true
test.js true

Additional information

Affected functions are, at least:

  • access
  • stat
  • readFile

Even though readdir lists filenames containg emojis, the functions used to access the files individually throw an ENOENT error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions