pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Pkg: Error reading from file

Open Trebossalol opened this issue 5 years ago • 9 comments

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.

Trebossalol avatar Mar 30 '21 22:03 Trebossalol

We need some more info to debug this problem

robertsLando avatar Mar 31 '21 07:03 robertsLando

Guys how do I change the icon exe?

Enmn avatar May 11 '21 17:05 Enmn

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 Aug 10 '21 00:08 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 Aug 16 '21 00:08 github-actions[bot]

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.

ziloka avatar Sep 13 '22 21:09 ziloka

there's still no solution for this issue?

mcuong223 avatar Mar 24 '23 13:03 mcuong223

Sorry, I never solved the issue.

Trebossalol avatar Mar 24 '23 13:03 Trebossalol

I also ran into this problem and have not yet found a solution.

lwx475784 avatar Jul 03 '23 09:07 lwx475784

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],
  ]);

postnd avatar Aug 03 '23 17:08 postnd