Pkg: Error reading from file
So i used pkg to compile my NodeJS App to an executable and its working fine, but after changing the icon of the executable with the help of resourcehacker, the executable got corrupted i assume. Console just says this "Pkg: Error reading from file " and exits.
We need some more info to debug this problem
Guys how do I change the icon exe?
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.
Just a workaround for those who get into this issue in the future. I was using upx to make the ~50mb, ~15mb but it makes my application for that error.
there's still no solution for this issue?
Sorry, I never solved the issue.
I also ran into this problem and have not yet found a solution.
instead of patching final executable you need to patch node binary instead
assume your package.json is something like this:
"bin": "./index.js",
"pkg": {
"outputPath": "dist",
"scripts": [
"./scripts/**/*"
],
"assets": [
"node_modules/**/*"
],
"targets": [
"node18-win-x64"
]
},
first, set download path SET PKG_CACHE_PATH=./cacheFolder
and run pkg .
it will downaload node18-win-x64 into ./cacheFolder/v3.4/fetched-v18.5.0-win-x64
then patch downloaded node binary
const rcedit = require("rcedit");
await rcedit( `./cacheFolder/v3.4/fetched-v18.5.0-win-x64`, {
"product-version": "1,0.0.0",
"file-version": "1,0.0.0",
icon: iconPath,
"version-string": {
FileDescription: "",
ProductName: "Custom Name",
LegalCopyright: "Custom Name",
OriginalFilename: "",
CompanyName: "Custom Name",
InternalName: "Custom Name",
},
});
after this step if you run code below pkg will issue that Binary hash does NOT match. Re-fetching...
to pass this rename fetched-v18.5.0-win-x64 to built-v18.5.0-win-x64 so that pkg thinks that your node binary is custom built
then make sure that PKG_CACHE_PATH comes before script, see https://github.com/vercel/pkg#environment
otherwise pkg will take the binary from his own path .pkg-cache located in user directory
to set PKG_CACHE_PATH programmatically, we need to set process.env.PKG_CACHE_PATH=path
const path = require("path");
process.env.PKG_CACHE_PATH = path.resolve(__dirname, "cacheFolder"); // Make sure this line comes before the next one
const pkg = require("pkg");
await pkg.exec([
"./package.json",
...["--d"],
...["--output", outputFilePath],
]);