Bun install or Skip NPM install for Workers
Hello, I am trying to deploy from a monorepo that uses
Bun
. That means we have workspace dependencies.
I noticed the env SKIP_DEPENDENCY_INSTALL
for Cloudflare Pages, is there something similar ― or does someone have some insights into the way to go about this?4 Replies
The goal here, is to skip the NPM install, so that I can use the build command to do
bun install
prior to the build.
I've added "packageManager": "[email protected]"
to the root package.json
of the monorepo as well as the subfolder containing the project, in hopes, that maybe Cloudflare could work out to use Bun ― with no luck.
Despite bun.lock
I figured I should try adding bun.lockb
to the root, and it seems that, that made Cloudflare detect a Bun environment. I guess Workers build just needs to update that🤷🏿♂️Can confirm
Btw you made sure to use latest bun by setting BUN_VERSION env var right (otherwise it's prob not using lockfile as it's on some old thing)
Ah maybe package manager field adds it, not sure
I figured this out for my monorepo!
Reading the docs here: https://developers.cloudflare.com/workers/ci-cd/builds/build-image/#skip-dependency-install
Bun is a supported build runtime. Here's what I did:
1. Specifying the Bun Version:
Environment Variable: You can set the BUN_VERSION environment variable in your Cloudflare Workers project settings (Settings > Build > Build Variables and Secrets) to specify the Bun version you want to use. BUN_VERSION = 1.1.33.
2. Skipping Automatic Dependency Installation:
SKIP_DEPENDENCY_INSTALL=true
Variable: To prevent Cloudflare from automatically running npm install, set the SKIP_DEPENDENCY_INSTALL build variable to 1 or true. This allows you to take full control of the installation process.
3. Custom Install Command:
Once you've skipped the automatic dependency installation, you can use the build command to run bun install (or any other custom installation steps you need). Your build command might look like this:
bun install
Deploy Command:
bun wrangler deploy
Path:
/packages/backend