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

Failed to find package "@oven/bun-linux-x64" error on npm i -g bun docker step #5545

Open
taranek opened this issue Sep 16, 2023 · 30 comments
Open
Labels
bug Something isn't working docker An issue that occurs when running in Docker

Comments

@taranek
Copy link

taranek commented Sep 16, 2023

What version of Bun is running?

1.0.1

What platform is your computer?

node:lts-alpine - docker image

What steps can reproduce the bug?

Dockerfile to reproduce the issue

FROM node:lts-alpine as build-stage
RUN npm install -g bun

npm install -g bun fails with an error:

+ npm install -g bun
npm ERR! code 1
npm ERR! path /usr/local/lib/node_modules/bun
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! Failed to find package "@oven/bun-linux-x64". You may have used the "--no-optional" flag when running "npm install".
npm ERR! Failed to find package "@oven/bun-linux-x64-baseline". You may have used the "--no-optional" flag when running "npm install".
npm ERR! Error: Failed to install package "bun"
npm ERR!     at /usr/local/lib/node_modules/bun/install.js:311:11
npm ERR!     at Generator.throw (<anonymous>)
npm ERR!     at rejected (/usr/local/lib/node_modules/bun/install.js:35:27)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

What is the expected behavior?

bun package is installed successfully

What do you see instead?

Docker build step fails with an installation error

Additional information

No response

@taranek taranek added the bug Something isn't working label Sep 16, 2023
@BOTKooper
Copy link

BOTKooper commented Sep 16, 2023

Can confirm, same for 1.0.0 and 1.0.2 (tried both basing from node:18-alpine), *-slim images work as expected

@Electroid
Copy link
Contributor

I wonder if this is because alpine node does not install optional dependencies by default? (I don't know this to be true, but that's my guess)

@BOTKooper
Copy link

BOTKooper commented Sep 16, 2023

I wonder if this is because alpine node does not install optional dependencies by default? (I don't know this to be true, but that's my guess)

doesn't look like that, it fails even with explicit --include=optional

@Electroid Electroid added the docker An issue that occurs when running in Docker label Sep 16, 2023
@squishyu
Copy link

squishyu commented Sep 16, 2023

Seeing some strange behavior. Bun itself installs, the postinstall script failed.
When installing with --ignore-scripts it properly installs the optional dependencides: @oven/bun-linux-x64 and @oven/bun-linux-x64-baseline

image

When I then manually run the postinstall script (npm run postinstall), it throws the original error.

Upon digging further, on the alpine image the binary file shows up in the bin directory.

bun binary is yellow

When trying to run it I got:

sh: ./bun: not found

Eventually stumbled upon this StackExchange post with the reason behind the error.

Turns out you need glibc to run Bun on Alpine.
To do that you can add this to your Dockerfile (from another StackExchange post)

RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add --no-cache --force-overwrite glibc-2.28-r0.apk

Which got Bun working for me:
image

And the npm install now finishes clean.
image

@BOTKooper
Copy link

@squishyu oof, this works, but i'm not sure if it solves the issue.

Sure, we can add this section to the docs (at least for now) and error message, but IMO solutions is not pretty and gonna divert some users from trying to use any images except for provided by bun

@taranek
Copy link
Author

taranek commented Sep 16, 2023

@squishyu Can you provide a sample Dockerfile?
In my case, it still throws an error while installing bun:

FROM node:lts-alpine as build-stage

RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add --no-cache --force-overwrite glibc-2.28-r0.apk

RUN npm install -g bun --ignore-scripts

throws the following error:

#20 0.219 Failed to find package "@oven/bun-linux-aarch64". You may have used the "--no-optional" flag when running "npm install".
#20 1.276 Failed to install package "@oven/bun-linux-aarch64" using "npm install". Error: ENOENT: no such file or directory, rename '/tmp/bun-pokKfm/node_modules/@oven/bun-linux-aarch64' -> 'node_modules/@oven/bun-linux-aarch64'
#20 1.276     at Object.renameSync (node:fs:1042:3)
#20 1.276     at rename (/usr/local/lib/node_modules/bun/bin/bun:202:21)
#20 1.276     at installBun (/usr/local/lib/node_modules/bun/bin/bun:364:23)
#20 1.276     at /usr/local/lib/node_modules/bun/bin/bun:336:7
#20 1.276     at Generator.next (<anonymous>)
#20 1.276     at /usr/local/lib/node_modules/bun/bin/bun:41:59
#20 1.276     at new Promise (<anonymous>)
#20 1.276     at __async (/usr/local/lib/node_modules/bun/bin/bun:27:51)
#20 1.276     at requireBun (/usr/local/lib/node_modules/bun/bin/bun:317:10)
#20 1.276     at /usr/local/lib/node_modules/bun/bin/bun:308:22 {
#20 1.276   errno: -2,
#20 1.276   syscall: 'rename',
#20 1.276   code: 'ENOENT',
#20 1.276   path: '/tmp/bun-pokKfm/node_modules/@oven/bun-linux-aarch64',
#20 1.276   dest: 'node_modules/@oven/bun-linux-aarch64'
#20 1.276 }
#20 2.585 Error: Failed to install package "bun"
#20 2.585     at /usr/local/lib/node_modules/bun/bin/bun:312:11
#20 2.585     at Generator.throw (<anonymous>)
#20 2.585     at rejected (/usr/local/lib/node_modules/bun/bin/bun:36:27)
#20 2.585     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
#20 ERROR: executor failed running [/bin/sh -c bun --version]: exit code: 1

@squishyu
Copy link

@squishyu Can you provide a sample Dockerfile? In my case, it still throws an error while installing bun:

@taranek Sorry, should've been more clear. Once you add the 4 RUN commands, you can use npm install -g bun without the --ignore-scripts

An example Dockerfile:

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add --no-cache --force-overwrite glibc-2.28-r0.apk
# Install Bun
RUN npm install -g bun

This leaves me with an image that can run Bun:
bun is working yay

@taranek
Copy link
Author

taranek commented Sep 16, 2023

@squishyu Strange, it still doesn't work on my M1:

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add --no-cache --force-overwrite glibc-2.28-r0.apk
# Install Bun
RUN npm install -g bun
RUN bun --version

but if I use --ignore-script flag, it seems to install properly, but throws a similar error as soon as I try to use bun command:

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add --no-cache --force-overwrite glibc-2.28-r0.apk
# Install Bun
RUN npm install -g bun
RUN bun --version
#9 [6/7] RUN npm install -g bun --ignore-scripts
#9 sha256:5e4c29e799f2bb5124ca0a4cce1206f32661110c7b8c57f490b20e7653d31c2c
#9 5.382 
#9 5.382 added 2 packages in 5s
#9 5.383 npm notice 
#9 5.383 npm notice New major version of npm available! 9.6.7 -> 10.1.0
#9 5.383 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.1.0>
#9 5.383 npm notice Run `npm install -g npm@10.1.0` to update!
#9 5.383 npm notice 
#9 DONE 5.5s

#10 [7/7] RUN bun --version
#10 sha256:b8ef78794d314fea8d1062c6b3c2d9a520845e93369e8d2fff4348ebd7a92deb
#10 0.215 Failed to find package "@oven/bun-linux-aarch64". You may have used the "--no-optional" flag when running "npm install".
#10 1.240 Failed to install package "@oven/bun-linux-aarch64" using "npm install". Error: ENOENT: no such file or directory, rename '/tmp/bun-HkNaak/node_modules/@oven/bun-linux-aarch64' -> 'node_modules/@oven/bun-linux-aarch64'
#10 1.240     at Object.renameSync (node:fs:1042:3)
#10 1.240     at rename (/usr/local/lib/node_modules/bun/bin/bun:202:21)
#10 1.240     at installBun (/usr/local/lib/node_modules/bun/bin/bun:364:23)
#10 1.240     at /usr/local/lib/node_modules/bun/bin/bun:336:7
#10 1.240     at Generator.next (<anonymous>)
#10 1.240     at /usr/local/lib/node_modules/bun/bin/bun:41:59
#10 1.240     at new Promise (<anonymous>)
#10 1.240     at __async (/usr/local/lib/node_modules/bun/bin/bun:27:51)
#10 1.240     at requireBun (/usr/local/lib/node_modules/bun/bin/bun:317:10)
#10 1.240     at /usr/local/lib/node_modules/bun/bin/bun:308:22 {
#10 1.240   errno: -2,
#10 1.240   syscall: 'rename',
#10 1.240   code: 'ENOENT',
#10 1.240   path: '/tmp/bun-HkNaak/node_modules/@oven/bun-linux-aarch64',
#10 1.240   dest: 'node_modules/@oven/bun-linux-aarch64'
#10 1.240 }
#10 2.504 Error: Failed to install package "bun"
#10 2.504     at /usr/local/lib/node_modules/bun/bin/bun:312:11
#10 2.504     at Generator.throw (<anonymous>)
#10 2.504     at rejected (/usr/local/lib/node_modules/bun/bin/bun:36:27)
#10 2.504     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
#10 ERROR: executor failed running [/bin/sh -c bun --version]: exit code: 1
------
 > [7/7] RUN bun --version:
------
executor failed running [/bin/sh -c bun --version]: exit code: 1

@squishyu

This comment was marked as resolved.

@squishyu
Copy link

squishyu commented Sep 16, 2023

@taranek Nevermind, my bad.
Turns out the dependency package in the example I provided - alpine-pkg-glibc - is x86_64 only.

The M1 Mac uses arm64 (or aarch64), therefore it needs different glibc binaries...
You can try using this Dockerfile, which uses docker-alpine-rpi-glibc-builder - though I would strongly suggest the binaries get moved elsewhere, as you'd be depending on some random person's personal Github repo.

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget https://raw.githubusercontent.com/athalonis/docker-alpine-rpi-glibc-builder/master/glibc-2.26-r1.apk
RUN apk add --allow-untrusted --force-overwrite glibc-2.26-r1.apk
RUN rm glibc-2.26-r1.apk
# Install Bun
RUN npm install -g bun

@seanwessmith
Copy link

@taranek Nevermind, my bad. Turns out the dependency package in the example I provided - alpine-pkg-glibc - is x86_64 only.

The M1 Mac uses arm64 (or aarch64), therefore it needs different glibc binaries... You can try using this Dockerfile, which uses docker-alpine-rpi-glibc-builder - though I would strongly suggest the binaries get moved elsewhere, as you'd be depending on some random person's personal Github repo.

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget https://raw.githubusercontent.com/athalonis/docker-alpine-rpi-glibc-builder/master/glibc-2.26-r1.apk
RUN apk add --allow-untrusted --force-overwrite glibc-2.26-r1.apk
RUN rm glibc-2.26-r1.apk
# Install Bun
RUN npm install -g bun

amazing, thank you. this works for me on Mac M1 Pro macOS Sonoma

@taranek
Copy link
Author

taranek commented Sep 17, 2023

@taranek Nevermind, my bad. Turns out the dependency package in the example I provided - alpine-pkg-glibc - is x86_64 only.

The M1 Mac uses arm64 (or aarch64), therefore it needs different glibc binaries... You can try using this Dockerfile, which uses docker-alpine-rpi-glibc-builder - though I would strongly suggest the binaries get moved elsewhere, as you'd be depending on some random person's personal Github repo.

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget https://raw.githubusercontent.com/athalonis/docker-alpine-rpi-glibc-builder/master/glibc-2.26-r1.apk
RUN apk add --allow-untrusted --force-overwrite glibc-2.26-r1.apk
RUN rm glibc-2.26-r1.apk
# Install Bun
RUN npm install -g bun

I can also confirm that it works. Thank you so much!

@squishyu
Copy link

Here's a simple combined version that checks CPU architecture and installs either the x86_64 or aarch64 version of glibc - so you can use the same Dockerfile on different machines.

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget

# Install glibc to run Bun
RUN if [[ $(uname -m) == "aarch64" ]] ; \
    then \
    # aarch64
    wget https://raw.githubusercontent.com/squishyu/alpine-pkg-glibc-aarch64-bin/master/glibc-2.26-r1.apk ; \
    apk add --no-cache --allow-untrusted --force-overwrite glibc-2.26-r1.apk ; \
    rm glibc-2.26-r1.apk ; \
    else \
    # x86_64
    wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk ; \
    wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub ; \
    apk add --no-cache --force-overwrite glibc-2.28-r0.apk ; \
    rm glibc-2.28-r0.apk ; \
    fi
# Install Bun
RUN npm install -g bun

@Synchro
Copy link

Synchro commented Sep 19, 2023

I found this gist that mentions a better solution - instead of pulling in a whole new source (with a fixed version number at that), install the gcompat alpine package, which is apparently the official way to provide support for glibc programs.

@squishyu
Copy link

@Synchro gcompat was among the first things I tried, it throws a different error...

> docker run --rm -it --entrypoint sh node:20-alpine                                            
/ # apk add --no-cache gcompat
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
(1/3) Installing musl-obstack (1.2.3-r2)
(2/3) Installing libucontext (1.2-r2)
(3/3) Installing gcompat (1.1.0-r1)
OK: 10 MiB in 20 packages
/ # npm install -g bun --ignore-scripts

added 3 packages in 10s
npm notice 
npm notice New major version of npm available! 9.8.1 -> 10.1.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.1.0
npm notice Run npm install -g npm@10.1.0 to update!
npm notice 
/ # cd /usr/local/lib/node_modules/bun/node_modules/@oven/bun-linux-x64-baseline/bin/
/usr/local/lib/node_modules/bun/node_modules/@oven/bun-linux-x64-baseline/bin # ./bun
Error relocating /usr/local/lib/node_modules/bun/node_modules/@oven/bun-linux-x64-baseline/bin/bun: unsupported relocation type 37
Error relocating /usr/local/lib/node_modules/bun/node_modules/@oven/bun-linux-x64-baseline/bin/bun: unsupported relocation type 37
Error relocating /usr/local/lib/node_modules/bun/node_modules/@oven/bun-linux-x64-baseline/bin/bun: unsupported relocation type 37

On arm64 it throws:

/usr/local/lib/node_modules/bun/node_modules/@oven/bun-linux-aarch64/bin # ./bun
Segmentation fault (core dumped)

Worth mentioning that while my solution isn't optimal, it only downloads a single package, installs it, then deletes the package file.

@Synchro
Copy link

Synchro commented Sep 19, 2023

It sounds like that's a problem in the package itself, rather than in the install process for it though? Was that reported to bun?

@taranek
Copy link
Author

taranek commented Sep 20, 2023

@Synchro Answering your 2nd question: this whole thread is a bug report in Bun's repository ;)

@Electroid
Copy link
Contributor

We just introduced a new Docker image: oven/bun:alpine. Does this issue still happen if you use that as a base?

@sumicet
Copy link

sumicet commented Jan 8, 2024

npm i -g bun
npm i

works on WSL

@10n37
Copy link

10n37 commented Feb 12, 2024

@taranek Nevermind, my bad. Turns out the dependency package in the example I provided - alpine-pkg-glibc - is x86_64 only.

The M1 Mac uses arm64 (or aarch64), therefore it needs different glibc binaries... You can try using this Dockerfile, which uses docker-alpine-rpi-glibc-builder - though I would strongly suggest the binaries get moved elsewhere, as you'd be depending on some random person's personal Github repo.

FROM node:18-alpine
# Add dependencies to get Bun working on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget https://raw.githubusercontent.com/athalonis/docker-alpine-rpi-glibc-builder/master/glibc-2.26-r1.apk
RUN apk add --allow-untrusted --force-overwrite glibc-2.26-r1.apk
RUN rm glibc-2.26-r1.apk
# Install Bun
RUN npm install -g bun

Works great. Thank you

@shtse8
Copy link

shtse8 commented Feb 21, 2024

We just introduced a new Docker image: oven/bun:alpine. Does this issue still happen if you use that as a base?

my project works fine with node:alpine with bun installed. but failed in running on oven/bun:alpine. sharp library will failed to run.

@stewones
Copy link

We just introduced a new Docker image: oven/bun:alpine. Does this issue still happen if you use that as a base?

please add support for node:cluster otherwise we can't use oven as docker base for production workload.

@itslewin
Copy link

This issue still persists.

@SaltFish001
Copy link

SaltFish001 commented Mar 28, 2024

Got same error when use node:20-alpine anf pnpm install bun

Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /builds/dkgy/template/fishbone/.pnpm-store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 274, reused 0, downloaded 274, added 2[73](https://gitlab.bmetdlc.cn/dkgy/template/fishbone/-/jobs/1849#L73)
Progress: resolved 274, reused 0, downloaded 274, added 274, done
.../esbuild@0.19.12/node_modules/esbuild postinstall$ node install.js
.../.pnpm/bun@1.0.35/node_modules/bun postinstall$ node install.js
.../.pnpm/bun@1.0.35/node_modules/bun postinstall: Failed to find package "@oven/bun-linux-x64-baseline". You may have used the "--no-optional" flag when running "npm install".
.../esbuild@0.19.12/node_modules/esbuild postinstall: Done
.../.pnpm/bun@1.0.35/node_modules/bun postinstall: Error: Failed to install package "bun"
.../.pnpm/bun@1.0.35/node_modules/bun postinstall:     at /builds/dkgy/template/fishbone/node_modules/.pnpm/bun@1.0.35/node_modules/bun/install.js:311:11
.../.pnpm/bun@1.0.35/node_modules/bun postinstall:     at Generator.throw (<anonymous>)
.../.pnpm/bun@1.0.35/node_modules/bun postinstall:     at rejected (/builds/dkgy/template/fishbone/node_modules/.pnpm/bun@1.0.35/node_modules/bun/install.js:35:27)
.../.pnpm/bun@1.0.35/node_modules/bun postinstall:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
.../.pnpm/bun@1.0.35/node_modules/bun postinstall: Failed
 ELIFECYCLE  Command failed with exit code 1.

@francoism90
Copy link

Same here, I'm confused how to solve this?

@XantreDev
Copy link

bun:alpine

We use bun for some scripts. It should work inside node:alpine images

@dum3ng
Copy link

dum3ng commented May 31, 2024

In node:20.12.2-alpine image, installed glibc-2.35-r1.apk, but still got the error when npm install -g bun@1.1.10

@van-fe
Copy link

van-fe commented Jun 12, 2024

This problem still exists, on bun@1.1.13.
But on bun@1.1.11, it won't appear.

@nodegin
Copy link

nodegin commented Jul 21, 2024

@XantreDev

FROM oven/bun:alpine AS bun
COPY --from=bun /usr/local/bin/bun /usr/local/bin/bun

@christophemarois
Copy link

Installing bun on alpine, be it from an official oven/bun:alpine docker image, the npm repository or other installation methods still doesn't work out of the box.

Adding gcompat makes the bun binary run, but produces segfaults in many modules, i.e. with tailwindcss.

So far, the only solution that works is #5545 (comment)

I'm really looking forward for the oven/bun:alpine alpine to work out of the box!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docker An issue that occurs when running in Docker
Projects
None yet
Development

No branches or pull requests