Error deploying Rails 7 app to fly.io with Tailwind and Flowbite
This error had me stumped for a few hours the other night. I'm using fly.io to host a project that I'm working on to help manage in-home child care providers run their business.
> [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#15 3.687
#15 3.687 Rebuilding...
#15 3.734 Error: Cannot find module '@tailwindcss/forms'
#15 3.734 Require stack:
#15 3.734 - /rails/config/tailwind.config.js
#15 3.734 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
#15 3.734 at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
#15 3.734 at Function.resolve (node:internal/modules/cjs/helpers:108:19)
#15 3.734 at _resolve (/snapshot/tailwindcss/node_modules/jiti/dist/jiti.js:1:241025)
#15 3.734 at jiti (/snapshot/tailwindcss/node_modules/jiti/dist/jiti.js:1:243309)
#15 3.734 at /rails/config/tailwind.config.js:54:5
#15 3.734 at jiti (/snapshot/tailwindcss/node_modules/jiti/dist/jiti.js:1:245784)
#15 3.734 at /snapshot/tailwindcss/lib/lib/load-config.js:37:30
#15 3.734 at loadConfig (/snapshot/tailwindcss/lib/lib/load-config.js:39:6)
#15 3.734 at Object.loadConfig (/snapshot/tailwindcss/lib/cli/build/plugin.js:135:49) {
#15 3.734 code: 'MODULE_NOT_FOUND',
#15 3.734 requireStack: [ '/rails/config/tailwind.config.js' ]
#15 3.734 }
#15 3.744 rails aborted!
#15 3.744 Command failed with exit 1: /rails/vendor/bundle/ruby/3.2.0/gems/tailwindcss-rails-2.0.29-x86_64-linux/exe/x86_64-linux/tailwindcss
...<removed some unuseful stack trace here>...
#15 3.745 Tasks: TOP => assets:precompile => tailwindcss:build
#15 3.745 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1
If this was my first deploy I'd think that something was going on with fly but this had been working perfectly. Then I realized it happened once I added Flowbite / tailwindcss to the mix. There are some workarounds to get Flowbite working with Turbo but that involved mixing importmap and node_modules a bit.
So the fix was to delete my DockerFile
, but not the fly.toml
and regenerate the DockerFile
with fly deploy. The let the fly console appropriately add the node build steps and allowed my deployments to work as intended.
