Bug with yarn and bun when running `rails new`

I think I’ve found a bug with the rails new command.

When I run this command, it sets up the project with both yarn and bun, creating two lockfiles.

rails new project_name -j=esbuild -c=tailwind -d=postgresql

Problems

Here are the duplicate lock files after running that command:

$ ls -1
app
bin
bun.lock <-- bun lock
config
config.ru
db
Dockerfile
Gemfile
Gemfile.lock
lib
log
node_modules
package.json
Procfile.dev
public
Rakefile
README.md
script
storage
test
tmp
vendor
yarn.lock <-- yarn lock

Here’s the Procfile.dev with duplicate package managers — yarn and bun:

web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: bun run build:css --watch

I change bun run to yarn like this:

web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: yarn build:css --watch

Then I delete the yarn.lock, bun.lock, and node_modules.

I run yarn again to reinstall the node_modules cleanly.

Then I run bin/rails test, and the bun.lock file reappears.

Then I delete the yarn.lock, bun.lock, and node_modules, and run yarn again.

I replace bunx from the "build:css" script in package.json with npx, resulting in this:

  "scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets",
    "build:css": "npx @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
  },

Then bin/rails test and the bun.lock file returns.

I don’t think there should be two lockfiles in the project.

System

M1 MacBook with Sequoia 15.3.2.

$ rails -v
Rails 8.0.2

$ bun -v
1.2.8

$ ruby -v
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]

$ yarn -v
1.22.22

(I’d rather be using pnpm, but I haven’t figured out how to do that yet.)

This problem also happens when running rake by itself. A bun.lock file appears.

Now I’m getting this other problem.

Edit: rails new was silently failing when yarn wasn’t installed after a Node version update with nvm.

I’m still getting the double lockfile once yarn is back on the path.

I’m still trying to figure this out, and I think the bug is in cssbundling-rails, so I’m going to file a bug there.