pkg: Failed to make bytecode for arm64 on Linux x86

What version of pkg are you using?

5.15.0

What version of Node.js are you using?

21.2.0

What operating system are you using?

Ubuntu

What CPU architecture are you using?

x86_64

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

node20-linuxstatic-arm64

Describe the Bug

Building a static binary for Linux ARM64 failes on Linux x86. For example, this command:

npx pkg -o index -t node20-linuxstatic-arm64 index.js

Generates the following error:

> pkg@5.15.0
> Warning Failed to make bytecode node20-arm64 for file /snapshot/yao-pkg-linuxstatic-arm64-bug/index.js

Adding the --debug flag to the build shows:

/home/rob/.pkg-cache/v3.5/fetched-v20.17.0-linuxstatic-arm64: 1: Syntax error: "(" unexpected
/home/rob/.pkg-cache/v3.5/fetched-v20.17.0-linuxstatic-arm64: 1: Syntax error: "(" unexpected
> Warning Failed to make bytecode node20-arm64 for file /snapshot/yao-pkg-linuxstatic-arm64-bug/index.js

I am able to generate an ARM64 static Linux binary on macOS.

Expected Behavior

A static Linux ARM64 is generated without warnings.

To Reproduce

I created a minimal example repository that demonstrates the problem:

git clone git@github.com:robvanderleek/yao-pkg-linuxstatic-arm64-bug.git
cd yao-pkg-linuxstatic-arm64-bug/
npm install
npx pkg -o index -t node20-linuxstatic-arm64 index.js

Not that:

npx pkg -o index -t node20-linuxstatic-x64 index.js

does not generate the warning.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

The --public seems to be working fine. I wonder what does it do? 🤔 I’ve read the README but still quite confusing.

It includes the script source for the project in the result binary instead of just the code cache bytecode. This is a little bit slower because of additional steps on startup for parsing/compiling, and is basically the same as running node main.js but everything bundled in the snapshot file system.

Getting code-cache-only to work is currently an open issue in Node 22, but should work with earlier versions.