Skip to content

Bun support #632

Description

Environment details

  • OS: macOS
  • OS version: Ventura 13.5.2 (22G91)
  • node-pty version: 1.0.0

Issue description

Does not work with bun (https://bun.sh)

index.ts

import pty from "node-pty";
const subprocess = pty.spawn("bash", [], {});

error

$ bun run --watch src/index.ts

error: Cannot find module "../build/Debug/pty.node" from "/Users/enes/Code/app/node_modules/node-pty/lib/unixTerminal.js"

error: Cannot find module "../build/Release/pty.node" from "/Users/enes/Code/app/node_modules/node-pty/lib/unixTerminal.js"

I've tried building it with node-gyp

$ cd node_modules/node-pty
$ bunx node-gyp-build

This creates the build/Release folders and its contents, but now it gives this vague error:

$ bun run --watch src/index.ts
dyld[5963]: missing symbol called
error: script "dev" exited with code 9 (SIGKILL)

package.json

{
	"name": "app",
	"version": "1.0.0",
	"module": "src/index.ts",
	"devDependencies": {
		"bun-types": "latest"
	},
	"scripts": {
		"test": "echo \"Error: no test specified\" && exit 1",
		"dev": "bun run --watch src/index.ts"
	},
	"dependencies": {
		"node-pty": "^1.0.0"
	}
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2021",
    "module": "ES2022",
    "moduleResolution": "node",
    "types": [
      "bun-types"
    ],
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

Activity

  1. Tyriar commented on Sep 26, 2023

    @Tyriar
    Contributor

    I tried this earlier and I don't think bun can work with node-gyp so it can't compile and package the binary

  2. terrywh commented on Feb 26, 2024

    @terrywh

    any new on this? all i can find is an unanswered stackoverflow: https://stackoverflow.com/questions/77950299/alternatives-to-node-pty-for-bun
    it would be very useful combined with the bun shell

  3. Tyriar commented on Feb 26, 2024

    @Tyriar
    Contributor

    As far as I'm aware bun doesn't work with nan/napi/node-gyp so this isn't possible.

  4. Jarred-Sumner commented on Mar 7, 2024

    @Jarred-Sumner

    There are two bugs here:

    1. node-gyp is supported in bun install, but there's a subtle bug with lifecycle scripts that cause it to not run correctly when there's a postinstall script and bindings.gyp both. Dylan Conway (@dylan-conway) is working on a fix. This bug impacts bun install, but does not impact the runtime.

    2. Bun's runtime implements napi, but node-pty depends on many Nan/V8 C++ API & libuv symbols which Bun does not implement yet.

    Those include:

    • __Z10PtyGetProcRKN3Nan20FunctionCallbackInfoIN2v85ValueEEE
    • _Z4initN2v85LocalINS_6ObjectEEE
    • _Z7PtyForkRKN3Nan20FunctionCallbackInfoIN2v85ValueEEE
    • _Z7PtyOpenRKN3Nan20FunctionCallbackInfoIN2v85ValueEEE
    • _Z9PtyResizeRKN3Nan20FunctionCallbackInfoIN2v85ValueEEE
    • _ZN2v811HandleScope12CreateHandleEPNS_8internal7IsolateEm
    • _ZN2v811HandleScopeC1EPNS_7IsolateE
    • _ZN2v811HandleScopeD1Ev
    • _ZN2v811HandleScopeD2Ev
    • _ZN2v812api_internal12ToLocalEmptyEv
    • _ZN2v812api_internal13DisposeGlobalEPm
    • _ZN2v812api_internal17FromJustIsNothingEv
    • _ZN2v812api_internal18GlobalizeReferenceEPNS_8internal7IsolateEm
    • _ZN2v814ObjectTemplate11NewInstanceENS_5LocalINS_7ContextEEE
    • _ZN2v814ObjectTemplate21SetInternalFieldCountEi
    • _ZN2v814ObjectTemplate3NewEPNS_7IsolateENS_5LocalINS_16FunctionTemplateEEE
    • _ZN2v816FunctionTemplate11GetFunctionENS_5LocalINS_7ContextEEE
    • _ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeEPKNS_9CFunctionEttt
    • _ZN2v820EscapableHandleScope6EscapeEPm
    • _ZN2v820EscapableHandleScopeC1EPNS_7IsolateE
    • _ZN2v86Number3NewEPNS_7IsolateEd
    • _ZN2v86Object16SetInternalFieldEiNS_5LocalINS_4DataEEE
    • _ZN2v86Object20SlowGetInternalFieldEi
    • _ZN2v86Object3GetENS_5LocalINS_7ContextEEEj
    • _ZN2v86Object3NewEPNS_7IsolateE
    • _ZN2v86Object3SetENS_5LocalINS_7ContextEEENS1_INS_5ValueEEES5_
    • _ZN2v86String11NewFromUtf8EPNS_7IsolateEPKcNS_13NewStringTypeEi
    • _ZN2v87Context6GlobalEv
    • _ZN2v87Integer3NewEPNS_7IsolateEi
    • _ZN2v87Isolate10GetCurrentEv
    • _ZN2v87Isolate14ThrowExceptionENS_5LocalINS_5ValueEEE
    • _ZN2v87Isolate17GetCurrentContextEv
    • _ZN2v88External3NewEPNS_7IsolateEPv
    • _ZN2v88internal35IsolateFromNeverReadOnlySpaceObjectEm
    • _ZN2v89Exception5ErrorENS_5LocalINS_6StringEEE
    • _ZN4node12MakeCallbackEPN2v87IsolateENS0_5LocalINS0_6ObjectEEENS3_INS0_8FunctionEEEiPNS3_INS0_5ValueEEENS_13async_contextE
    • _ZN4node13EmitAsyncInitEPN2v87IsolateENS0_5LocalINS0_6ObjectEEENS3_INS0_6StringEEEd
    • _ZN4node16EmitAsyncDestroyEPN2v87IsolateENS_13async_contextE
    • _ZNK2v85Array6LengthEv
    • _ZNK2v85Value10IsFunctionEv
    • _ZNK2v85Value12BooleanValueEPNS_7IsolateE
    • _ZNK2v85Value12IntegerValueENS_5LocalINS_7ContextEEE
    • _ZNK2v85Value7IsArrayEv
    • _ZNK2v85Value8IsNumberEv
    • _ZNK2v85Value8ToStringENS_5LocalINS_7ContextEEE
    • _ZNK2v85Value9IsBooleanEv
    • _ZNK2v85Value9ToIntegerENS_5LocalINS_7ContextEEE
    • _ZNK2v86String6LengthEv
    • _ZNK2v86String9WriteUtf8EPNS_7IsolateEPciPii
    • _ZNK2v88External5ValueEv
    • uv_async_init
    • uv_async_send
    • uv_close
    • uv_default_loop
    • uv_thread_create

    To find this information, I ran nm -g build/Release/pty.node.

  5. Tyriar commented on Mar 7, 2024

    @Tyriar
    Contributor

    Jarred Sumner (@Jarred-Sumner) thanks for the info. Can you clarify whether there's anything that should happen in this repo or if it's all on bun's side? I don't mind accepting changes to improve compatibility but don't plan on doing them myself as we don't use bun currently.

  6. karlhorky commented on Sep 18, 2024

    @karlhorky

    I think a good part of it is on the side of Bun:

    Please follow along in #4290

    190n is actively working on supporting V8 C++ APIs in Bun

  7. Tyriar commented on Dec 17, 2024

    @Tyriar
    Contributor

    Closing this as out of scope, but contributions are always welcome to improve compatibility.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions