Rails 7 & ESbuild

Has anyone successfully tried to deploy Rails 7 Alpha with ESBuild?

I have the following render-build.sh file, but it doesn’t seem to make the assets available:

#!/usr/bin/env bash

# exit on error

set -o errexit

bundle lock --add-platform x86_64-linux

bundle install

bundle exec rake assets:precompile

bundle exec rake assets:clean

./node_modules/.bin/esbuild app/javascript/*.* --bundle --outdir=app/assets/builds

./node_modules/.bin/tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css

bundle exec rake db:migrate

Hello!

I was able to make a Rails 7 Alpha test app with ESBuild, although I didn’t add anything in particular to my render-build.sh file - it just matches what’s in our docs example.

Have you tried starting a new project with the command rails project-name --database=postgresql esbuild --css tailwind before deploying to Render? I’m not sure if you were starting from a fresh project or migrating an older one, so I’m curious to see the results.

(post deleted by author)

Hello! I had the same issue than you. Happened when migrating from importmaps to esbuild and ignoring the generated js because it’s too big and recreate it in the render-build script.

What I did is to use the esbuild bundle command before the assets:precompile command so it actually creates the file. Then on the config/assets.rb file I included the file by name. That will precompile it along and include it in the prod app.

I am also running into this issue, and found some very bizarre workarounds.

What I found is that ‘rake assets:precompile’ seems to run fine according to the logs - it seems to run esbuild first and then the sprockets compile. However after deploy, the rails app just gives me the application.js is not present in the asset pipeline error. Even more strangely, when I manually re-run ‘rake assets:precompile’ in a SSH session, and I restart the rails app (kill the puma process), the rails app is now able to find that file, and everything is working.

It gets even weirder.

Since two runs of ‘rake assets:precompile’ seems to work, why not automate? My build script literally has two consecutive lines like this:

bundle exec rake assets:precompile
bundle exec rake assets:precompile

And that builds everything as it should.

It almost seems as if the order matters of what gets built first: esbuild perhaps needs to be run after sprockets or whatever. But who knows.

I just created an account to reply to you: this is working, and I have no idea WHY! it is driving me crazy. funny thing is that I had the exact SAME issue trying to deploy my app on google cloud, so it could be something with Rails…

Move the tailwind and esbuild compilation steps into a build task, and then enhance the precompile task:

namespace :javascript do
  desc "Build your JavaScript bundle"
  task :build do
    system "npm install && npm run build"
  end
end

Rake::Task["assets:precompile"].enhance(["javascript:build"])