Spiker985 / x-terminal-reloaded

An xterm based package for providing terminals inside your workspace.
https://web.pulsar-edit.dev/packages/x-terminal-reloaded
Other
10 stars 3 forks source link

ARM architecture incompatibility #27

Open ShankarWarang opened 1 year ago

ShankarWarang commented 1 year ago

Description

The package installs but crashes upon trying open the terminal every time on M1, supposedly on all ARM64 chips.

Versions

Atom: 1.102.0 arm64 Electron: 12.2.3 OS: macOS 13.2.1 Thrown From: x-terminal-reloaded package 14.1.4

Stack Trace

Failed to activate the x-terminal-reloaded package

At dlopen(/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node, 0x0001): tried: '/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node' (no such file), '/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

Error: dlopen(/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node, 0x0001): tried: '/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node' (no such file), '/Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
    at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1138:18)
    at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1846)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.o._load (electron/js2c/renderer_init.js:33:379)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (/app.asar/src/native-compile-cache.js:67:27)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/unixTerminal.js:27:11)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/unixTerminal.js:279:3)
    at Module._compile (/app.asar/src/native-compile-cache.js:120:30)
    at /app.asar/src/compile-cache.js:252:23)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.o._load (electron/js2c/renderer_init.js:33:379)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (/app.asar/src/native-compile-cache.js:67:27)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/index.js:14:20)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/index.js:52:3)
    at Module._compile (/app.asar/src/native-compile-cache.js:120:30)
    at /app.asar/src/compile-cache.js:252:23)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.o._load (electron/js2c/renderer_init.js:33:379)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (/app.asar/src/native-compile-cache.js:67:27)
    at Object.<anonymous> (element.js:23:1)
    at Object.<anonymous> (element.js:746:67)
    at Module._compile (/app.asar/src/native-compile-cache.js:120:30)
    at /app.asar/src/compile-cache.js:252:23)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)

Non-Core Packages installed

atom-beautify 0.33.4 
busy-signal 2.0.1 
file-icons 2.1.47 
intentions 2.1.1 
language-javascript-jsx 0.3.7 
linter 3.4.0 
linter-js-standard 7.0.0 
linter-ui-default 3.4.1 
x-terminal-reloaded 14.1.4 

Thank you!

Spiker985 commented 1 year ago

Interesting, if you execute pulsar --package rebuild does this error go away?

Basically, node-pty-prebuilt-multiarch is supposed to take some information from your machine (architecture, and os) and use that to check for proper electron headers to download/rebuild node-pty which is used to emulate the terminal

However, it looks like your device picked darwin for your OS (correct) and x64 for your architecture (incorrect)

ShankarWarang commented 1 year ago

I tried pulsar --package rebuild and arch -arm64 pulsar --package rebuild. Both the time facing the same issue.

Spiker985 commented 1 year ago

Alright, can you do this for me:

  1. Open Pulsar
  2. Open Dev Tools (normally Ctrl + Shift + I on non-mac) or you can click View -> Toggle Developer Tools
  3. Click Console
  4. Type os = require('os'), hit enter
  5. Type os.arch(), hit enter
  6. type os.platform(), hit enter
  7. Screenshot or paste the result

I'm trying to figure out if it's one of the scripts included in node-pty-prebuilt-multiarch having a problem determining what architecture you're on, or if it's a problem of ppm.

ShankarWarang commented 1 year ago

Sure, here it is:

os = require('os')
{arch: ƒ, cpus: ƒ, endianness: ƒ, freemem: ƒ, getPriority: ƒ, …}
os.arch()
"arm64"
os.platform()
"darwin"

Thanks.

ShankarWarang commented 1 year ago

As you mentioned, looks like ppm is missing something while ported from apm? If so, should I open an issue on Pulsar's github?

Spiker985 commented 1 year ago

Hmm, not yet

Can you do pulsar --package install x-terminal-reloaded --verbose, I reverted an incompatible version of a package a short while ago, and so there's a new version 14.1.5 out

The verbose piece is the most important part of the command, because that should tell me what header version node-pty-prebuilt-multiarch is trying to use

ShankarWarang commented 1 year ago

Looks like it is using a wrong prebuild despite node using the right OS and architecture:

prebuild-install info begin Prebuild-install version 6.1.4
prebuild-install info looking for local prebuild @ prebuilds/node-pty-prebuilt-multiarch-v0.10.0-electron-v87-darwin-x64.tar.gz
prebuild-install info looking for cached prebuild @ /Users/1/.pulsar/.apm/_prebuilds/673d55-node-pty-prebuilt-multiarch-v0.10.0-electron-v87-darwin-x64.tar.gz
prebuild-install http request GET https://github.com/oznu/node-pty-prebuilt-multiarch/releases/download/v0.10.0/node-pty-prebuilt-multiarch-v0.10.0-electron-v87-darwin-x64.tar.gz
prebuild-install http 404 https://github.com/oznu/node-pty-prebuilt-multiarch/releases/download/v0.10.0/node-pty-prebuilt-multiarch-v0.10.0-electron-v87-darwin-x64.tar.gz
prebuild-install WARN install No prebuilt binaries found (target=12.2.3 runtime=electron arch=x64 libc= platform=darwin)
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/Applications/Pulsar.app/Contents/Resources/app/ppm/bin/node',
gyp verb cli   '/Applications/Pulsar.app/Contents/Resources/app/ppm/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild'
gyp verb cli ]
gyp info using node-gyp@5.1.0
gyp info using node@16.0.0 | darwin | arm64

Do you need any specific/full log?

ShankarWarang commented 1 year ago

Also for all the releases from v0.10.0 onwards, only v0.10.1-pre.5 has node-pty-prebuilt-multiarch binary available for electron-v87.

Spiker985 commented 1 year ago

Also for all the releases from v0.10.0 onwards, only v0.10.1-pre.5 has node-pty-prebuilt-multiarch binary available for electron-v87.

Yeah, I'm in the process of trying to make the CI pass properly on the https://github.com/Spiker985/x-terminal-reloaded/tree/feature-bundle-node-pty-prebuilt-multiarch branch

The problem is that the CI is doing the even weirder thing of detecting that the proper version is 93 on mac and linux - and is failing to even find the windows version, so it's building it from scratch.

You may be able to navigate to ~/.pulsar/packages/x-terminal-reloaded, open the package.json, change the dependency to 0.10.1-pre.5, save it, and then run pulsar -p rebuild --verbose and see if it will oblige the change in dependency - it should, since as far as I know it doesn't validate the package data, it simply rebuilds native modules

ShankarWarang commented 1 year ago

After updating the dependency version in package.json and rebuilding packages, it was still returning the same error. So I used npm i node-pty-prebuilt-multiarch@0.10.1-pre.5 command to update the dependency after deleting the node-pty-prebuilt-multiarch folder under the node_modules and then rebuilt packages.

Now the package is failing at activation stage:

Stack Trace

Failed to activate the x-terminal-reloaded package

At Cannot find module '../build/Release/pty.node'
Require stack:
- /Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/prebuild-loader.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/unixTerminal.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/index.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/src/element.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/src/x-terminal.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/module-utils.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/package.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/package-manager.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/atom-environment.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/initialize-application-window.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/static/index.html

Error: Cannot find module '../build/Release/pty.node'
Require stack:
- /Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/prebuild-loader.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/unixTerminal.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/index.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/src/element.js
- /Users/1/.pulsar/packages/x-terminal-reloaded/src/x-terminal.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/module-utils.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/package.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/package-manager.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/atom-environment.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/src/initialize-application-window.js
- /Applications/Pulsar.app/Contents/Resources/app.asar/static/index.html
    at Module._resolveFilename (internal/modules/cjs/loader.js:887:15)
    at o._resolveFilename (electron/js2c/renderer_init.js:33:1118)
    at Function.Module._resolveFilename (/app.asar/src/module-cache.js:317:28)
    at Module._load (internal/modules/cjs/loader.js:732:27)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.o._load (electron/js2c/renderer_init.js:33:379)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (/app.asar/src/native-compile-cache.js:67:27)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/prebuild-loader.js:6:11)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/prebuild-loader.js:20:3)
    at Module._compile (/app.asar/src/native-compile-cache.js:120:30)
    at /app.asar/src/compile-cache.js:252:23)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.o._load (electron/js2c/renderer_init.js:33:379)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (/app.asar/src/native-compile-cache.js:67:27)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/unixTerminal.js:25:25)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/unixTerminal.js:266:3)
    at Module._compile (/app.asar/src/native-compile-cache.js:120:30)
    at /app.asar/src/compile-cache.js:252:23)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.o._load (electron/js2c/renderer_init.js:33:379)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (/app.asar/src/native-compile-cache.js:67:27)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/index.js:14:20)
    at /packages/x-terminal-reloaded/node_modules/node-pty-prebuilt-multiarch/lib/index.js:52:3)
    at Module._compile (/app.asar/src/native-compile-cache.js:120:30)
    at /app.asar/src/compile-cache.js:252:23)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.o._load (electron/js2c/renderer_init.js:33:379)
juliaanvaneijndt commented 1 year ago

Exact same issue here.

mauricioszabo commented 1 year ago

This is probably the same problem that it happens with this code: https://github.com/pulsar-edit/pulsar/issues/359

Part of the fix is here: https://github.com/pulsar-edit/pulsar/pull/493. TL;DR; - we inherited some code from Atom that checks if a package rebuild failed previously when we tried to compile it inside the editor so that's why sometimes rebuilding doesn't work;

Second part is that we're trying to make rebuild better - I have a proof-of-concept in "userspace" (meaning - it's a Pulsar package) that is currently trying to replace the way we install dependencies and compile them. Let's see if that works, and if it does, we can integrate it into the editor itself

mcguffin commented 11 months ago

I've been struggling on the same issue on an M2 chip. Obviously node-pty-prebuilt-multiarch was not detecting the architecture correctly, so I had to do the job. After downloading the correct prebuild pty.node from the repo (in my case it was electron-v87-darwin-arm64) I got it to work.

This is what I did:

  1. cd ~/.pulsar/packages/x-terminal-reloaded
  2. Change the node-pty-prebuilt-multiarch dependency from 0.10.0 to ^0.10.1-pre5 in package.json as suggested
  3. pulsar -p rebuild --verbose
  4. Download matching prebuild for my cpu from the 0.10.1 pre 5 release page (on an M1/M2 it's node-pty-prebuilt-multiarch-v0.10.1-pre.5-electron-v87-darwin-arm64.tar.gz The important part is electron-v87)
  5. replace node_modules/node-pty-prebuilt-multiarch/build/Release/pty.node with the downlaoded one.
  6. Restart Pulsar => macOS refuses to execute pty.node => quit pulsar
  7. Allow execution of pty.node in system security settings
  8. start pulsar
  9. Open a terminal
  10. Celebrate (recommended but not required)
lewallen commented 11 months ago

@mcguffin That worked for me on a mac m1, thanks a lot!

thatcomputerguy0101 commented 4 months ago

I just switched my installation to use @homebridge/node-pty-prebuilt-multiarch (v0.11.13) instead of the original (there appears to have been a change in ownership, since the repository link for the original now redirects to the homebridge version), and it started working without problem. v0.11.14 ups the minimum supported Electron version to 16, so that doesn't work with the current default Electron.