Skip to content

Cross-compiling from Linux to macOS produces non-functional binaries #183

Open

Description

@tasshi-me

What version of pkg are you using?

6.9.0

What version of Node.js are you using?

20.19.5, 22.20.0, 24.10.0

What operating system are you using?

macOS 15

What CPU architecture are you using?

arm64

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

linux-x64,win-x64,macos-arm64

Describe the Bug

When I build a macOS binary on Ubuntu using pkg, the build succeeds without any errors.
However, the resulting executable doesn’t run the packaged app — instead, it starts a plain Node.js process.

I checked #87 and #181, but couldn’t determine whether they are related.

Expected Behavior

The packaged application should start normally, as it does when built natively on macOS.

To Reproduce

# Step 1. Build executables for macOS on a Linux x64 machine
echo 'console.log("Hello, World!");' > index.js
npx @yao-pkg/pkg@6.9.0 --sea index.js -t macos-x64,macos-arm64
# => executables are generated (index-arm64, index-x64)

# Step 2. Copy executables (index-arm64, index-x64) to a macOS machine

# Step 3. Run executables on a macOS machine (I checked on Apple M1)
./index-arm64
# => Node.js REPL starts
# Welcome to Node.js v22.20.0.
# Type ".help" for more information.
# >
# Error: Could not open history file.
# REPL session history will not be persisted.
# >

./index-x64
# => Node.js REPL starts
# Welcome to Node.js v22.20.0.
# Type ".help" for more information.
# >
# Error: Could not open history file.
# REPL session history will not be persisted.
# >

Repro Repo

A minimal reproduction using CI is available here:
https://github.com/tasshi-playground/repro-pkg-cross-platform-issue

Build on linux
Built on macos

Activity

  1. changed the title [-]Cross-compilation from Linux to macOS seems broken[/-] [+]Cross-compiling from Linux to macOS produces non-functional binaries[/+] on Oct 17, 2025
  2. robertsLando commented on Oct 17, 2025

    @robertsLando
    Member

    Tried with --public?

  3. tasshi-me commented on Oct 18, 2025

    @tasshi-me
    Author

    @robertsLando

    Thanks for the quick response! I tried adding --public, but the behavior didn’t change.

    ## Command I tried
    npx @yao-pkg/pkg@6.9.0 --sea --public index.js -t macos-x64,macos-arm64
    

    The --public option seems to have no effect when SEA is enabled.
    It's passed to the Maker in walker.ts, but the Maker isn't called in sea.ts.

  4. robertsLando commented on Oct 20, 2025

    @robertsLando
    Member

    Sorry I missed the part where you mentioned you are using --sea. The issues you have mentioned here are related to the original pkg way, sea uses a completely different way to pack binaries.

    I'm following steps described in https://nodejs.org/api/single-executable-applications.html to produce binaries, could you try to manually do them and tell me if it works in that way? I'm super busy in this weeks and I'm not sure when I can look at this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions