visual-studio-codenestjsemojipinojs

Why node-emoji won't print properly on nestjs/pino logger?


I am investigating a strange behavior from a Nestjs project I am developing, that wants to use @NestJs/Pino logger to display emojis in the terminal's logs. However, node-emoji only display the emoji properly in the terminal if I use console.log(emoji.get('gear')). However, if I use pino.info(emoji.get('gear') + ' test string.....'), I get an output of: [1646848210346] INFO (18320 on DESKTOP-2H3BS4O): **⚙️** test string...... Where "⚙️", is supposed to be the emoji printed by the logger at the terminal.

I have seek support at Nestjs's discord, but there, a user used my minimum reproduction repository, and the problem did not happened in their environment. I am using Windows/VSCode which leads me to believe that the problem might be something with my environment. So, here is the link to the repo:link, to run the project:

MY VSCode Env:

My PC environment:

Information about package.json, package-lock.json, and confiuraton for @nestjs/pino logger can be found at the linked repo.


Solution

  • This is known limitation of Node.js that was discovered by Pino back in 2018. Pino team proposes this workaround in their documentation.

    Run this command in terminal:

    chcp 65001

    If you use nodemon and pino-pretty, you may have to add something like this to package.json to make it work in VSCode terminal (powershell by default).

      "scripts": {
        "start": "node index.js",
        "dev": "chcp 65001 && nodemon index.js | pino-pretty"
      },
    

    Then, running npm run dev will work.