Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esbuild fails to install when using an asdf version of yarn/npm #2785

Closed
lakinwecker opened this issue Dec 30, 2022 · 11 comments
Closed

esbuild fails to install when using an asdf version of yarn/npm #2785

lakinwecker opened this issue Dec 30, 2022 · 11 comments

Comments

@lakinwecker
Copy link

lakinwecker commented Dec 30, 2022

I use asdf to manage my nodejs versions as I switch between various projects with varying dependencies. However, it seems that the esbuild install fails to determine the appropriate path to the esbuild binary that gets installed and it falls back to using a system path /usr/bin/esbuild which does not contain the binary.

I can work around it by linking the installed esbuild into my /usr/bin:
-> sudo ln -sf /home/lakin/.config/yarn/global/node_modules/@esbuild/linux-x64/bin/esbuild /usr/bin/esbuild

I'm actually trying to install redwoodjs, so don't mind the references to it in this log of what happens. Also, I've tried with raw npm:

npm install --save-exact --global esbuild

and

npm install --save-exact esbuild

and none of them work. The log output:

-> rm -rf /home/lakin/.config/yarn/global/node_modules/esbuild/

redwood-test on  main 
-> rm -rf /home/lakin/.config/yarn/global/node_modules/@esbuild/

redwood-test on  main 
-> which yarn
/home/lakin/.asdf/shims/yarn

redwood-test on  main 
-> yarn global add esbuild
yarn global v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
error /home/lakin/.config/yarn/global/node_modules/esbuild: Command failed.
Exit code: 1
Command: node install.js
Arguments: 
Directory: /home/lakin/.config/yarn/global/node_modules/esbuild
Output:
node:internal/errors:863
  const err = new Error(message);
              ^

Error: Command failed: /home/lakin/.asdf/installs/nodejs/19.1.0/bin/node /home/lakin/.config/yarn/global/node_modules/esbuild/bin/esbuild --version
node:child_process:924
    throw err;
    ^

<ref *1> Error: spawnSync /usr/bin/esbuild ENOENT
    at Object.spawnSync (node:internal/child_process:1117:20)
    at spawnSync (node:child_process:871:24)
    at Object.execFileSync (node:child_process:914:15)
    at Object.<anonymous> (/home/lakin/.config/yarn/global/node_modules/esbuild/bin/esbuild:2:26)
    at Module._compile (node:internal/modules/cjs/loader:1205:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawnSync /usr/bin/esbuild',
  path: '/usr/bin/esbuild',
  spawnargs: [ '--version' ],
  error: [Circular *1],
  status: null,
  signal: null,
  output: null,
  pid: 0,
  stdout: null,
  stderr: null
}

Node.js v19.1.0

    at checkExecSyncError (node:child_process:885:11)
    at Object.execFileSync (node:child_process:921:15)
    at validateBinaryVersion (/home/lakin/.config/yarn/global/node_modules/esbuild/install.js:90:32)
    at /home/lakin/.config/yarn/global/node_modules/esbuild/install.js:241:5 {
  status: 1,
  signal: null,
  output: [
    null,
    Buffer(0) [Uint8Array] [],
    Buffer(1020) [Uint8Array] [
      110, 111, 100, 101,  58,  99, 104, 105, 108, 100,  95, 112,
      114, 111,  99, 101, 115, 115,  58,  57,  50,  52,  10,  32,
       32,  32,  32, 116, 104, 114, 111, 119,  32, 101, 114, 114,
       59,  10,  32,  32,  32,  32,  94,  10,  10,  60, 114, 101,
      102,  32,  42,  49,  62,  32,  69, 114, 114, 111, 114,  58,
       32, 115, 112,  97, 119, 110,  83, 121, 110,  99,  32,  47,
      117, 115, 114,  47,  98, 105, 110,  47, 101, 115,  98, 117,
      105, 108, 100,  32,  69,  78,  79,  69,  78,  84,  10,  32,
       32,  32,  32,  97,
      ... 920 more items
    ]
  ],
  pid: 1064878,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(1020) [Uint8Array] [
    110, 111, 100, 101,  58,  99, 104, 105, 108, 100,  95, 112,
    114, 111,  99, 101, 115, 115,  58,  57,  50,  52,  10,  32,
     32,  32,  32, 116, 104, 114, 111, 119,  32, 101, 114, 114,
     59,  10,  32,  32,  32,  32,  94,  10,  10,  60, 114, 101,
    102,  32,  42,  49,  62,  32,  69, 114, 114, 111, 114,  58,
     32, 115, 112,  97, 119, 110,  83, 121, 110,  99,  32,  47,
    117, 115, 114,  47,  98, 105, 110,  47, 101, 115,  98, 117,
    105, 108, 100,  32,  69,  78,  79,  69,  78,  84,  10,  32,
     32,  32,  32,  97,
    ... 920 more items
  ]
}

Node.js v19.1.0
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

redwood-test on  main 
!-> which esbuild
which: no esbuild in (/home/lakin/.asdf/shims:/home/lakin/.asdf/bin:/home/lakin/.cargo/bin:/home/lakin/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/tools:/opt/android-sdk/tools/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/lakin/.local/bin:/home/lakin/bin:/home/lakin/gbin:/home/lakin/.pgenv/bin:/home/lakin/.pgenv/pgsql/bin:/home/lakin/.local/share/coursier/bin:/home/lakin/.local/bin:/home/lakin/bin:/home/lakin/gbin:/home/lakin/.pgenv/bin:/home/lakin/.pgenv/pgsql/bin:/home/lakin/.local/share/coursier/bin)

redwood-test on  main 
!-> cat /home/lakin/.config/yarn/global/node_modules/esbuild/bin/esbuild
#!/usr/bin/env node
require('child_process').execFileSync("/usr/bin/esbuild", process.argv.slice(2), { stdio: 'inherit' });

redwood-test on  main 
-> ls -la /usr/bin/esbuild
"/usr/bin/esbuild": No such file or directory (os error 2)

redwood-test on  main 
!-> ls -la /home/lakin/.config/yarn/global/node_modules/@esbuild/linux-x64/bin/esbuild 
.rwxr-xr-x 8.7M lakin 30 Dec 08:42 /home/lakin/.config/yarn/global/node_modules/@esbuild/linux-x64/bin/esbuild

redwood-test on  main 
-> 

I'd be happy to take a shot at fixing this, but I don't have experience with packaging in node, so might need a couple pointers of how to go about testing it once I've made the change as well as some amount of direction as to what the appropriate fix should be. I would assume that you'd want to properly detect the final destination of the binary file somehow and then inject that into the esbuild script

@evanw
Copy link
Owner

evanw commented Dec 30, 2022

Do you perhaps have the ESBUILD_BINARY_PATH variable set to something? That is a way to provide a custom path for the esbuild binary. I don’t think esbuild would ever use the path /usr/bin/esbuild otherwise. Also what does the file /home/lakin/.config/yarn/global/node_modules/esbuild/bin/esbuild look like?

@lakinwecker
Copy link
Author

Yup, I certainly do. No idea where that came from:

-> env | grep ESBUILD_BINARY_PATH
ESBUILD_BINARY_PATH=/usr/bin/esbuild

@lakinwecker
Copy link
Author

-> cat /home/lakin/.config/yarn/global/node_modules/esbuild/bin/esbuild 
#!/usr/bin/env node
require('child_process').execFileSync("/usr/bin/esbuild", process.argv.slice(2), { stdio: 'inherit' });

@lakinwecker
Copy link
Author

I'll close this and figure out what set that variable for me.

@evanw
Copy link
Owner

evanw commented Jan 10, 2023

Did you ever figure out what it was? Other people are also reporting this as a bug in esbuild now too.

Edit: Looks like this bug was introduced by https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=esbuild

evanw added a commit that referenced this issue Jan 10, 2023
@lakinwecker
Copy link
Author

I did not directly figure out what it was, but I suspect that it was from an AUR build of esbuild, yes. A different AUR package that I was using depends on the AUR esbuild, which had been run recently. So my suspicion is that it somehow polluted my env.

@lakinwecker
Copy link
Author

It came back after an AUR build of esbuild today. So I'm pretty sure it's from that.

@lakinwecker
Copy link
Author

lakinwecker commented Jan 15, 2023

Yeah, I found it. It installs a file in /etc/profile.d/esbuild.sh

cat /etc/profile.d/esbuild.sh 
export ESBUILD_BINARY_PATH='/usr/bin/esbuild'

@evanw
Copy link
Owner

evanw commented Jan 15, 2023

Thanks for confirming. I tried to work around this from the installer side of things by ignoring ESBUILD_BINARY_PATH if the file doesn't exist, although I wasn't able to test it myself. So hopefully this isn't a problem anymore in recent versions of esbuild.

@hamman3223
Copy link

hamman3223 commented Nov 13, 2023

I had the same issue. I simply launched command esbuild --version manually and observed that permissions on esbuild binary was restricted. Try to chmod esbuild binary

@greenhat616
Copy link

@hamman3223 I had the same issue. I simply launched command esbuild --version manually and observed that permissions on esbuild binary was restricted. Try to chmod esbuild binary

Same issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants