Error when including emoji in filename for write-file - NodeJS 20 only

I'm getting the following error when including an emoji in the filename for the write-file node:

failed to write to file: Error: ENOENT: no such file or directory, open

I've only seen this in Node-RED 3.10 on Windows 11 with NodeJS 20.

When I go back to NodeJS 18 or 16, there's no such problem. I also don't see the problem with the Node-RED Docker container, but that one is using NodeJS 16. Would be nice if someone could check this with NodeJS 20 on a Linux system.

Here's a simple sample flow to demonstrate the issue:

[
    {
        "id": "cc10a716472a843a",
        "type": "inject",
        "z": "454622bdf78b0ca1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 60,
        "wires": [
            [
                "24674f9a0ae35479"
            ]
        ]
    },
    {
        "id": "1782c517158a3408",
        "type": "debug",
        "z": "454622bdf78b0ca1",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 580,
        "y": 60,
        "wires": []
    },
    {
        "id": "24674f9a0ae35479",
        "type": "file",
        "z": "454622bdf78b0ca1",
        "name": "",
        "filename": "/data/test/test-okay-👌.txt",
        "filenameType": "str",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 370,
        "y": 60,
        "wires": [
            [
                "1782c517158a3408"
            ]
        ]
    }
]

I'm amazed that Windows even allows that, it had never even occurred to me to try! But it does indeed seem to work from File Explorer and PowerShell!

I'm afraid I don't have node.js v20 to hand but it would be worth trying a simple node.js app to see if the fs module supports it, it may be a node.js v20 limitation rather than an node-red one.

See - (Windows) FS can not handle certain characters in file name · Issue #48673 · nodejs/node · GitHub

I think maybe someone fixed a bug in v20 :slight_smile:

Thanks, that's useful. So the problem is specifically prevented in NodeJS 18.18.1 and later, but awaits fixes from an upstream project for the 20 branch.

Indeed. An interesting example of how a small change in a dependency can have a large impact. :slight_smile:

At least the reason is known and an upstream fix exists.

Of course, I might ask the question - why would you want emoji's in your filenames? Feels like that is something that is bound to cause issues somewhere. I doubt many tools get tested against that.

Though I might also throw some emoji's into my file names at work just for the fun of trying to find places where they break things. :rofl:

1 Like

Yeah, exactly - I was testing the custom nodes that the company I work at is developing :grinning:. Dealing with non-ascii characters is a risk that sometimes gets overlooked. So using accents and Chinese characters is quite normal. Using emoji's is more of an edge case, but that's what you have testers for, to try to find the edge cases :innocent:.

It's not likely to trigger a problem for us now, but what about an application that stores chats in messaging apps? Thread titles in chat apps can easily have emoji nowadays, and filename sanitation should (in my opinion) not be too rigid by default, limiting itself to known forbidden characters on operating systems like slashes.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.