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

Support for bun runtime #2 #4152

Closed
5 tasks done
niels-bosman opened this issue Jul 3, 2024 · 4 comments
Closed
5 tasks done

Support for bun runtime #2 #4152

niels-bosman opened this issue Jul 3, 2024 · 4 comments
Labels

Comments

@niels-bosman
Copy link

niels-bosman commented Jul 3, 2024

Duplicate of #3511 which is still happening for me.

Possible bug

When building and running a Hono API via Bun in Docker(compose) using the sharp package the following error happens:

presentation-creator-1  | error: Could not load the "sharp" module using the linux-arm64 runtime
presentation-creator-1  | Possible solutions:
presentation-creator-1  | - Ensure optional dependencies can be installed:
presentation-creator-1  |     npm install --include=optional sharp
presentation-creator-1  |     yarn add sharp --ignore-engines
presentation-creator-1  | - Ensure your package manager supports multi-platform installation:
presentation-creator-1  |     See https://sharp.pixelplumbing.com/install#cross-platform
presentation-creator-1  | - Add platform-specific dependencies:
presentation-creator-1  |     npm install --os=linux --cpu=arm64 sharp

Versions:

Here is my Dockerfile:

FROM oven/bun:1.1.17-alpine as base
WORKDIR /usr/src/app

FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb bunfig.toml /temp/dev/
RUN cd /temp/dev && bun install

FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/dev/node_modules node_modules
COPY --from=prerelease /usr/src/app/src/server.ts .
COPY --from=prerelease /usr/src/app/package.json .

USER bun
EXPOSE 3000/tcp
ENTRYPOINT ["bun", "run", "--bun", "--watch", "src/server.ts"]

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System:
    OS: macOS 15.0
    CPU: (12) arm64 Apple M3 Pro
    Memory: 118.38 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    Yarn: 1.22.22 - ~/Code/SlideSpeak/slidespeak-monorepo/node_modules/.bin/yarn
    npm: 10.8.1 - ~/Code/SlideSpeak/slidespeak-monorepo/node_modules/.bin/npm
    pnpm: 8.15.4 - ~/.nvm/versions/node/v20.11.0/bin/pnpm
    bun: 1.1.17 - ~/.bun/bin/bun
  npmPackages:
    sharp: 0.33.4 => 0.33.4

Does this problem relate to file caching?

  • Adding sharp.cache(false) does not fix this problem.

Does this problem relate to images appearing to have been rotated by 90 degrees?

  • Using rotate() or keepExif() does not fix this problem.

What are the steps to reproduce?

Create a simple hono app with Bun, import sharp and dockerize it like the example above.

What is the expected behaviour?

Everything should work.

@lovell
Copy link
Owner

lovell commented Jul 3, 2024

Did you see #3511 (comment) ?

@niels-bosman
Copy link
Author

niels-bosman commented Jul 3, 2024

Did you see #3511 (comment) ?

@lovell Tried with oven/bun:1.1.17-debian, oven/bun:1.1.17-slim & oven/bun:1.1.17-alpine and all getting the same error. Does this mean total incompatibility with Bun via docker? All works fine when I run things on my Mac myself without dockerizing.

@lovell
Copy link
Owner

lovell commented Jul 3, 2024

The Debian-based container should work.

It looks like you're using a relatively complex Dockerfile that is selectively copying files between layers and from the host so make sure you understand what each directive is doing. For example, this COPY directive could potentially overwrite the contents of node_modules inside the container with the contents from the host, outside the container.

COPY . .

@niels-bosman
Copy link
Author

@lovell Thanks for the help. Turned out I was being stupid and locally symlinking my node_modules (causing the error).

So instead of this:

  xxx:
    volumes:
      - ./xxx:/usr/src/app
    ports:
      - '8080:8000'

It needed to be this:

  xxx:
    volumes:
      - ./xxx:/usr/src/app
      - /usr/src/app/node_modules <<< to ignore the node modules for mounting a volume
    ports:
      - '8080:8000'

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

No branches or pull requests

2 participants