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

Bun fails to install esbuild binary #6176

Closed
dnicolson opened this issue Sep 29, 2023 · 17 comments
Closed

Bun fails to install esbuild binary #6176

dnicolson opened this issue Sep 29, 2023 · 17 comments
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client

Comments

@dnicolson
Copy link

What version of Bun is running?

1.0.3

What platform is your computer?

Darwin 23.0.0 arm64 arm

What steps can reproduce the bug?

bun install esbuild@^0.19.4
bun run esbuild

What is the expected behavior?

The esbuild binary to be executed.

What do you see instead?

The following message:

Error: The package "@esbuild/darwin-x64" could not be found, and is needed by esbuild.

Additional information

Using npm or pnpm results in a compiled binary at node_modules/esbuild/bin/esbuild but with Bun this is just a JavaScript file.

Based on evanw/esbuild#3398 (comment) it doesn't seem to be an esbuild issue.

@dnicolson dnicolson added the bug Something isn't working label Sep 29, 2023
@Electroid Electroid added the bun install Something that relates to the npm-compatible client label Sep 29, 2023
@cyfung1031
Copy link
Contributor

cyfung1031 commented Sep 29, 2023

esbuild needs options like bun run esbuild --bundle index.js --outfile=out.js...

btw, it can run in my MacOS.

1.0.3
Darwin 21.6.0 arm64 arm

Have you added the bun/bin into PATH?
Possible due to #5990

@dnicolson
Copy link
Author

Arguments for esbuild are not needed to check if the binary is correct:

cat << EOF > package.json
{
  "scripts": {
    "esbuild": "esbuild"
  },
  "dependencies": {
    "esbuild": "^0.19.4"
  }
}
EOF

npm install
npm run esbuild | head

Output:

> esbuild
> esbuild


Usage:
  esbuild [options] [entry points]

Documentation:
  https://esbuild.github.io/

@dnicolson
Copy link
Author

The path .bun/bin is in the PATH environment variable.

@cyfung1031
Copy link
Contributor

cyfung1031 commented Sep 29, 2023

bun install esbuild@^0.19.4
bun run esbuild | head
bun --version
uname -mprs
Screen Shot 2023-09-30 at 5 25 36

@dnicolson
Copy link
Author

dnicolson commented Sep 29, 2023

There is also an issue with Go NPM that might be related.

npm:

npm install irestore
ls -l node_modules/.bin
total 9800
lrwxr-xr-x  1 dave  staff       31 Sep 29 22:47 go-npm@ -> ../@go-task/go-npm/bin/index.js
-rwxr-xr-x  1 dave  staff  5014736 Sep 29 22:47 irestore*

Bun:

bun install irestore
ls -l node_modules/.bin
total 0
lrwxrwxrwx  1 dave  staff  31 Sep 29 22:47 go-npm@ -> ../@go-task/go-npm/bin/index.js

@cyfung1031
Copy link
Contributor

There is also an issue with Go NPM that might be related.

npm:

npm install irestore
ls -l node_modules/.bin
total 9800
lrwxr-xr-x  1 dave  staff       31 Sep 29 22:47 go-npm@ -> ../@go-task/go-npm/bin/index.js
-rwxr-xr-x  1 dave  staff  5014736 Sep 29 22:47 irestore*

Bun:

bun install irestore
ls -l node_modules/.bin
total 0
lrwxrwxrwx  1 dave  staff  31 Sep 29 22:47 go-npm@ -> ../@go-task/go-npm/bin/index.js

might relate to this #6138

@ImBIOS
Copy link
Contributor

ImBIOS commented Oct 1, 2023

bun install esbuild@^0.19.4
bun run esbuild | head
bun --version
uname -mprs
Screen Shot 2023-09-30 at 5 25 36

executing bun run esbuild | head gave me:

Error: 
You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.

Specifically the "@esbuild/darwin-arm64" package is present but this platform
needs the "@esbuild/darwin-x64" package instead. People often get into this
situation by installing esbuild with npm running inside of Rosetta 2 and then
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
2 is Apple's on-the-fly x86_64-to-arm64 translation service).

If you are installing with npm, you can try ensuring that both npm and node are
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
changing how you installed npm and/or node. For example, installing node with
the universal installer here should work: https://nodejs.org/en/download/. Or
you could consider using yarn instead of npm which has built-in support for
installing a package on multiple platforms simultaneously.

If you are installing with yarn, you can try listing both "arm64" and "x64"
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.

Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.

UPDATE: I'll add more information:

uname -mprs: Darwin 23.0.0 arm64 arm

bun --version: 1.0.3

envinfo:


  System:
    OS: macOS 14.0
    CPU: (8) x64 Apple M2
    Memory: 45.69 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 14.21.3 - ~/.proto/bin/node
  Languages:
    Bash: 3.2.57 - /bin/bash
    Go: 1.21.0 - /usr/local/go/bin/go
    Java: 17.0.8.1 - /usr/bin/javac
    Perl: 5.30.3 - /usr/bin/perl
    PHP: 8.2.11 - /Users/ImBIOS/Library/Application Support/Herd/bin/php
    Protoc: 3.21.9 - /usr/local/bin/protoc
    Python: 3.11.5 - /opt/homebrew/opt/[email protected]/libexec/bin/python
    Python3: 3.11.5 - /opt/homebrew/bin/python3
    Ruby: 2.6.10 - /usr/bin/ruby
    Rust: 1.70.0 - /Users/ImBIOS/.cargo/bin/rustc
  npmPackages:
    @fontsource/inter: 5.0.8 => 5.0.8 
    @mailchimp/mailchimp_marketing: ^3.0.80 => 3.0.80 
    @next/bundle-analyzer: 13.5.3 => 13.5.3 
    @svgr/webpack: ^8.1.0 => 8.1.0 
    @tailwindcss/forms: ^0.5.6 => 0.5.6 
    @tailwindcss/typography: ^0.5.10 => 0.5.10 
    @types/react: ^18.2.24 => 18.2.24 
    @types/tailwindcss: ^3.0.11 => 3.1.0 
    @typescript-eslint/eslint-plugin: ^6.7.3 => 6.7.3 
    @typescript-eslint/parser: ^6.7.3 => 6.7.3 
    autoprefixer: ^10.4.16 => 10.4.16 
    contentlayer: 0.3.4 => 0.3.4 
    cross-env: ^7.0.3 => 7.0.3 
    dedent: ^1.5.1 => 1.5.1 
    esbuild: ^0.19.4 => 0.19.4 
    eslint: ^8.50.0 => 8.50.0 
    eslint-config-next: 13.5.3 => 13.5.3 
    eslint-config-prettier: ^9.0.0 => 9.0.0 
    eslint-plugin-prettier: ^5.0.0 => 5.0.0 
    file-loader: ^6.2.0 => 6.2.0 
    github-slugger: ^2.0.0 => 2.0.0 
    globby: 13.2.2 => 13.2.2 
    gray-matter: ^4.0.3 => 4.0.3 
    husky: ^8.0.3 => 8.0.3 
    image-size: 1.0.2 => 1.0.2 
    inquirer: ^9.2.11 => 9.2.11 
    lint-staged: ^14.0.1 => 14.0.1 
    mdx-bundler: ^9.2.1 => 9.2.1 
    next: 13.5.3 => 13.5.3 
    next-contentlayer: 0.3.4 => 0.3.4 
    next-themes: ^0.2.1 => 0.2.1 
    postcss: ^8.4.31 => 8.4.31 
    preact: ^10.18.1 => 10.18.1 
    prettier: ^3.0.3 => 3.0.3 
    prettier-plugin-tailwindcss: ^0.5.4 => 0.5.4 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    reading-time: 1.5.0 => 1.5.0 
    rehype-autolink-headings: ^7.0.0 => 7.0.0 
    rehype-citation: ^1.0.2 => 1.0.2 
    rehype-katex: ^7.0.0 => 7.0.0 
    rehype-preset-minify: 7.0.0 => 7.0.0 
    rehype-prism-plus: ^1.6.3 => 1.6.3 
    rehype-slug: ^6.0.0 => 6.0.0 
    remark: ^15.0.1 => 15.0.1 
    remark-footnotes: ^4.0.1 => 4.0.1 
    remark-gfm: ^4.0.0 => 4.0.0 
    remark-math: ^6.0.0 => 6.0.0 
    sharp: ^0.32.6 => 0.32.6 
    smoothscroll-polyfill: ^0.4.4 => 0.4.4 
    tailwindcss: ^3.3.3 => 3.3.3 
    typescript: ^5.2.2 => 5.2.2 
    unist-util-visit: ^5.0.0 => 5.0.0 


@ImBIOS
Copy link
Contributor

ImBIOS commented Oct 1, 2023

bun install esbuild@^0.19.4
bun run esbuild | head
bun --version
uname -mprs
Screen Shot 2023-09-30 at 5 25 36

executing bun run esbuild | head gave me:

Error: 
You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.

Specifically the "@esbuild/darwin-arm64" package is present but this platform
needs the "@esbuild/darwin-x64" package instead. People often get into this
situation by installing esbuild with npm running inside of Rosetta 2 and then
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
2 is Apple's on-the-fly x86_64-to-arm64 translation service).

If you are installing with npm, you can try ensuring that both npm and node are
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
changing how you installed npm and/or node. For example, installing node with
the universal installer here should work: https://nodejs.org/en/download/. Or
you could consider using yarn instead of npm which has built-in support for
installing a package on multiple platforms simultaneously.

If you are installing with yarn, you can try listing both "arm64" and "x64"
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.

Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.

UPDATE: I'll add more information:

uname -mprs: Darwin 23.0.0 arm64 arm

bun --version: 1.0.3

envinfo:


  System:
    OS: macOS 14.0
    CPU: (8) x64 Apple M2
    Memory: 45.69 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 14.21.3 - ~/.proto/bin/node
  Languages:
    Bash: 3.2.57 - /bin/bash
    Go: 1.21.0 - /usr/local/go/bin/go
    Java: 17.0.8.1 - /usr/bin/javac
    Perl: 5.30.3 - /usr/bin/perl
    PHP: 8.2.11 - /Users/ImBIOS/Library/Application Support/Herd/bin/php
    Protoc: 3.21.9 - /usr/local/bin/protoc
    Python: 3.11.5 - /opt/homebrew/opt/[email protected]/libexec/bin/python
    Python3: 3.11.5 - /opt/homebrew/bin/python3
    Ruby: 2.6.10 - /usr/bin/ruby
    Rust: 1.70.0 - /Users/ImBIOS/.cargo/bin/rustc
  npmPackages:
    @fontsource/inter: 5.0.8 => 5.0.8 
    @mailchimp/mailchimp_marketing: ^3.0.80 => 3.0.80 
    @next/bundle-analyzer: 13.5.3 => 13.5.3 
    @svgr/webpack: ^8.1.0 => 8.1.0 
    @tailwindcss/forms: ^0.5.6 => 0.5.6 
    @tailwindcss/typography: ^0.5.10 => 0.5.10 
    @types/react: ^18.2.24 => 18.2.24 
    @types/tailwindcss: ^3.0.11 => 3.1.0 
    @typescript-eslint/eslint-plugin: ^6.7.3 => 6.7.3 
    @typescript-eslint/parser: ^6.7.3 => 6.7.3 
    autoprefixer: ^10.4.16 => 10.4.16 
    contentlayer: 0.3.4 => 0.3.4 
    cross-env: ^7.0.3 => 7.0.3 
    dedent: ^1.5.1 => 1.5.1 
    esbuild: ^0.19.4 => 0.19.4 
    eslint: ^8.50.0 => 8.50.0 
    eslint-config-next: 13.5.3 => 13.5.3 
    eslint-config-prettier: ^9.0.0 => 9.0.0 
    eslint-plugin-prettier: ^5.0.0 => 5.0.0 
    file-loader: ^6.2.0 => 6.2.0 
    github-slugger: ^2.0.0 => 2.0.0 
    globby: 13.2.2 => 13.2.2 
    gray-matter: ^4.0.3 => 4.0.3 
    husky: ^8.0.3 => 8.0.3 
    image-size: 1.0.2 => 1.0.2 
    inquirer: ^9.2.11 => 9.2.11 
    lint-staged: ^14.0.1 => 14.0.1 
    mdx-bundler: ^9.2.1 => 9.2.1 
    next: 13.5.3 => 13.5.3 
    next-contentlayer: 0.3.4 => 0.3.4 
    next-themes: ^0.2.1 => 0.2.1 
    postcss: ^8.4.31 => 8.4.31 
    preact: ^10.18.1 => 10.18.1 
    prettier: ^3.0.3 => 3.0.3 
    prettier-plugin-tailwindcss: ^0.5.4 => 0.5.4 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    reading-time: 1.5.0 => 1.5.0 
    rehype-autolink-headings: ^7.0.0 => 7.0.0 
    rehype-citation: ^1.0.2 => 1.0.2 
    rehype-katex: ^7.0.0 => 7.0.0 
    rehype-preset-minify: 7.0.0 => 7.0.0 
    rehype-prism-plus: ^1.6.3 => 1.6.3 
    rehype-slug: ^6.0.0 => 6.0.0 
    remark: ^15.0.1 => 15.0.1 
    remark-footnotes: ^4.0.1 => 4.0.1 
    remark-gfm: ^4.0.0 => 4.0.0 
    remark-math: ^6.0.0 => 6.0.0 
    sharp: ^0.32.6 => 0.32.6 
    smoothscroll-polyfill: ^0.4.4 => 0.4.4 
    tailwindcss: ^3.3.3 => 3.3.3 
    typescript: ^5.2.2 => 5.2.2 
    unist-util-visit: ^5.0.0 => 5.0.0 

I fixed this problem by changing my node from 14 to 18 using proto, and allowing npm through engines in pakcage.json.

@cyfung1031
Copy link
Contributor

cyfung1031 commented Oct 2, 2023

Yes, I am using Node 18.

I believe there were some fundamental changes for Node 18 (and 16?) which is the version decided to make support on MacOS M1 M2 chips.

And then esbuild in some versions started to drop the support for Node 14 and going to 18.
(so new versions of esbuild cannot be used in Win 7)


But it is wried, node should not be the dependency when bun is used.

@alexcberk
Copy link

try adding "trustedDependencies": ["esbuild"], to package.json

@dnicolson
Copy link
Author

try adding "trustedDependencies": ["esbuild"], to package.json

That is in improvement with Bun v1.0.4 but still mixes architectures, unlike npm:

bun install v1.0.4 (745b6b94)
 + [email protected]
[esbuild] Failed to find package "@esbuild/darwin-x64" on the file system

This can happen if you use the "--no-optional" flag. The "optionalDependencies"
package.json feature is used by esbuild to install the correct binary executable
for your current platform. This install script will now attempt to work around
this. If that fails, you need to remove the "--no-optional" flag to use esbuild.

[esbuild] Trying to install package "@esbuild/darwin-x64" using npm

npm:

file node_modules/esbuild/bin/esbuild
node_modules/esbuild/bin/esbuild: Mach-O 64-bit executable x86_64
file node_modules/@esbuild/darwin-x64/bin/esbuild
node_modules/@esbuild/darwin-x64/bin/esbuild: Mach-O 64-bit executable x86_64

Bun v1.0.4:

file node_modules/esbuild/bin/esbuild
node_modules/esbuild/bin/esbuild: a /usr/bin/env node script text executable, ASCII text
file node_modules/@esbuild/darwin-arm64/bin/esbuild
node_modules/@esbuild/darwin-arm64/bin/esbuild: Mach-O 64-bit executable arm64

Bun v1.0.4 with "trustedDependencies": ["esbuild"]:

file node_modules_trusted/esbuild/bin/esbuild
node_modules_trusted/esbuild/bin/esbuild: Mach-O 64-bit executable x86_64
file node_modules_trusted/@esbuild/darwin-arm64/bin/esbuild
node_modules_trusted/@esbuild/darwin-arm64/bin/esbuild: Mach-O 64-bit executable arm64

@Jonatthu
Copy link

Jonatthu commented Oct 5, 2023

"trustedDependencies": [
"@sentry/cli",
"supabase",
"@supabase"
]

I still have to manually trigger post install and install scripts of these 3, the trustedDaependencies is not doing anything

Mind providing a disable flag of this "feature" on the bun config, please?

it is clear is not ready

@alexcberk
Copy link

alexcberk commented Oct 11, 2023

nvm install 18 --arch arm64

this is working for me in bun v1.0.5

I had to make sure I was running the ARM version of node.js on my Mac M1. The x86 version runs under Rosetta and will throw architecture mismatch errors with arm64 binaries (such as esbuild).

@anhtuank7c
Copy link

@AcBerk Thank you so much. Its work for me.

@salomartin
Copy link

Same issues with trying to use shopify-cli, where it fails to install the binaries for cloudfront altogether, even if you add it to trustedDependencies. Haven't found a fix. The post install scripts try to execute some commands via node, probably related but haven't manage to spend time debugging yet. Maybe some aliasing of node to bun could work around a good chunk of issues.

@anhtuank7c
Copy link

@salomartin Do you use nvm?
I found that there is a problem with nvm node package. I have to remove the nvm completely and install nodejs from brew. Its work without asking the architecture as above.

@nektro
Copy link
Member

nektro commented Oct 24, 2024

given that i'm unable to reproduce this behavior even with the version of Bun listed in the original post, i'm leaning towards this being an architecture/rosetta mismatch issue and not something on Bun's side

❯ bun x [email protected] install esbuild@^0.19.4
bun add v1.0.3 (25e69c71)

 installed [email protected] with binaries:
  - esbuild


 2 packages installed [485.00ms]

❯ bun x [email protected] run esbuild            

Usage:
  esbuild [options] [entry points]

Documentation:
  https://esbuild.github.io/

am currently wrestling with rosetta to see if i can reproduce using x86 bun on arm mac but atm i think @alexcberk's solution is the right one. if anyone is still able to reproduce this using arm bun on arm mac please let us know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client
Projects
None yet
Development

No branches or pull requests

9 participants