Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exe packaged by yao-pkg changed Intl.DateTimeFormat output on windows #101

Open
armgong opened this issue Oct 10, 2024 · 5 comments
Open

Comments

@armgong
Copy link

armgong commented Oct 10, 2024

What version of pkg are you using?

5.15.0

What version of Node.js are you using?

v20.18.0

What operating system are you using?

windows

What CPU architecture are you using?

x86_64

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

node20-win-x64 node18-win-x64

Describe the Bug

the packaged exe file output wrong format datetime string.
why this happend , still no any idea!!!
before package run on console , the output are

# node index.js
2024/10/10 20:32:34

run the packaged exe , the output are

 test-yao.exe
2024-10-10 20 ├Minute: 34┤ ├Second: 9┤

Expected Behavior

output the same as run on console

To Reproduce

there is code :
index.js

const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738));
const dateTimeFormatter = new Intl.DateTimeFormat("zh-CN", {
    year: 'numeric',
    hour: 'numeric',
    minute: 'numeric',
    second: 'numeric',
    day: '2-digit',
    month: '2-digit',
});
console.log(dateTimeFormatter.format(Date.now()));

and the package.json

{
  "name": "test-yao",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",  
  "bin": {
    "test-yao": "index.js"
  },
  "pkg": {    
    "targets": [
      "node20-win-x64"
    ]
  }
}

first run on windows cmd console , its output ar

Administrator@WIN-Z230 d:\src\test-yao
# node index.js
2024/10/10 20:32:34

then package it with yao-pkg 5.15.0

pkg . --public -C gzip -t node20-win-x64 -o test-yao.exe

run the test-yao.exe , the output is

 test-yao.exe
2024-10-10 20 ├Minute: 34┤ ├Second: 9┤
@armgong
Copy link
Author

armgong commented Oct 10, 2024

here is the picture, also test package with node16 18 20 and 22.
16 output is right,

# test-yao-16.exe
2024-10-10 22:02:09

18 and 20 is wrong
{927B8A69-0DE4-4C27-BEA9-FEC66257FB8C}
22 output it totally error

# test-yao-22.exe
node:internal/modules/cjs/loader:1254
  throw err;
  ^

Error: Cannot find module 'C:\snapshot\test-yao\index.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1251:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
    at Module._load (node:internal/modules/cjs/loader:1077:27)
    at Function.runMain (pkg/prelude/bootstrap.js:1983:12)
    at node:internal/main/run_main_module:30:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v22.9.0

@robertsLando
Copy link
Member

robertsLando commented Oct 10, 2024

reason is that patches are using small icu so Initl may behave different than expected. Reason behind this choice is to keep binary size small. You can verify icu version by running node -p "process.versions.icu"

About nodejs 22 issue there is already a fix for it just waiting a new patch to come out

@armgong
Copy link
Author

armgong commented Oct 10, 2024

maybe this issue is not relate to icu?
the orgin pkg with 18.15.0 packaged exefile output is correct, and its size is 39.9 MB , seems it also use small icu?

@robertsLando
Copy link
Member

robertsLando commented Oct 10, 2024

the orgin pkg with 18.15.0 packaged exefile output is correct, and its size is 39.9 MB , seems it also use small icu?

Based on the logs you provided I don't see it is working even on node 18 #101 (comment)

The last time we built node 16 has been long time ago so maybe the build changed. I should check the commits history on https://github.com/yao-pkg/pkg-fetch

I suggest you to give a try packaging the app with: https://www.npmjs.com/package/full-icu module listed on package.json

@armgong
Copy link
Author

armgong commented Oct 11, 2024

Did more test today,the result is strange, confusing now.

the origin pkg wiht node18.5.0 , DateTimeFormat is "zh-CN" or undefined

const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738));
const dateTimeFormatter = new Intl.DateTimeFormat("zh-CN", {
    year: 'numeric',
    hour: 'numeric',
    minute: 'numeric',
    second: 'numeric',
    day: '2-digit',
    month: '2-digit',
    hour12:false,
});
console.log(dateTimeFormatter.format(Date.now()));

both output is correct

C:\src>cd test-pkg

C:\src\test-pkg>node index.js
2024/10/11 08:30:29

C:\src\test-pkg>pkg . --public -C gzip -t node18-win-x64 -o test18.exe
> pkg@5.8.1
compression:  GZip
> Fetching base Node.js binaries to PKG_CACHE_PATH
  fetched-v18.5.0-win-x64             [====================] 100%

C:\src\test-pkg>test18.exe
2024-10-11 8:31:17

the yao-pkg wiht node18.20.4 , DateTimeFormat is "zh-CN" or undefined are wrong

but when change DateTimeFormat is "en-US" ,the result is correct

# test-yao-18.exe
10/11/2024, 8:43:31 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants