pkg
pkg copied to clipboard
Intl i18n date formatting not working when using pkg
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
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
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
This is still an issue.
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
This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.
Here's a working example/solution to get correctly formatted dates with pkg
: https://github.com/vercel/pkg/issues/1731#issuecomment-1317191357