2023-10-13
Weird Rails 7 build break due to outdated npm
I am working on a new Ruby on Rails project with a friend. We bumped into a few development blockers that I have never experienced before. It turns out that if you are using an outdated version on npm, the pacakage.json
which gets generated when you create a new Rails application will not include the necessary scripts needed in order to get ./bin/dev
working.
Assuming your Ruby on Rails application is using cssbundling and jsbundling–if you see any build errors when trying to run the server with ./bin/dev
you may want to try the following:
- First update your node version to a newer stable version. I set mine to
18.17.1
. I use asdf to manage ruby and nodejs versions.asdf local nodejs 18.17.1
- Then update your npm version. I am using version
8.19.4
.npm install -g npm@8.19.4
- re-install cssbundling
rails css:install:bootstrap
- re-install jsbundling
rails javascript:install:esbuild
In package.json
, check to see if the scripts
key includes five items for the value. Your Procfile.dev
should look like the following:
web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: yarn watch:css
After updating npm and node version, yarn commands should work and you should be able to run the server with ./bin/dev
.