pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Intl i18n date formatting not working when using pkg

Open NMisko opened this issue 2 years ago • 3 comments

What version of pkg are you using?

5.5.2

What version of Node.js are you using?

16.14.2

What operating system are you using?

Debian Bullseye

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node16-linux

Describe the Bug

When using the Intl package in a file that has been packaged by pkg, date formatting into non-english formats doesn't work. Explicitly enabling full ICU should not be necessary on node 16.

In example below, output is Date formatted correctly in German: false, got January.

Expected Behavior

Using the Intl package to format dates should work.

In example below, output is Date formatted correctly in German: true, got Januar.

To Reproduce

Dockerfile to reproduce bug

FROM node:16-bullseye

RUN yarn global add pkg

RUN echo 'const january = new Date(9e8); \
  const german = new Intl.DateTimeFormat("de", { month: "long" }); \
  console.log(`Date formatted correctly in German: ${german.format(january) === "Januar"}, got ${german.format(january)}`)' > test.js

RUN echo '{"name": "intl.pkg.test"}' > package.json

RUN pkg -t node16-linux -o /app/test --config ./package.json test.js

ENTRYPOINT /app/test

Dockerfile to reproduce expected behaviour

FROM node:16-bullseye

RUN echo 'const january = new Date(9e8); \
  const german = new Intl.DateTimeFormat("de", { month: "long" }); \
  console.log(`Date formatted correctly in German: ${german.format(january) === "Januar"}, got ${german.format(january)}`)' > test.js

ENTRYPOINT node test.js

NMisko avatar Mar 21 '22 17:03 NMisko

Interestingly there is an article by vercel stating that full ICU should work with node 14 out of the box. Our experience is that this does not work.

https://vercel.com/support/articles/how-can-i-use-full-icu-with-vercel

MaxMediaPictures avatar Apr 05 '22 08:04 MaxMediaPictures

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] avatar Jul 05 '22 00:07 github-actions[bot]

This is still an issue.

NMisko avatar Jul 09 '22 17:07 NMisko

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] avatar Oct 08 '22 00:10 github-actions[bot]

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

github-actions[bot] avatar Oct 13 '22 00:10 github-actions[bot]

Here's a working example/solution to get correctly formatted dates with pkg : https://github.com/vercel/pkg/issues/1731#issuecomment-1317191357

TBG-FR avatar Nov 16 '22 15:11 TBG-FR