Should Upgrading Rails guide mention package.json/npm/yarn?

The Upgrading Ruby on Rails Guide has no mention of package.json or your npm package dependencies.

But Rails is of course increasingly moving to using such.

A Rails app generated under Rails 6.0.x might have a package.json that looks like:

{
  "name": "rails6034demo",
  "private": true,
  "dependencies": {
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "4.3.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "webpack-dev-server": "^3.11.0"
  }
}

A Rails app generated with 6.1.x might have a package.json that looks like:

{
  "name": "rails61app",
  "private": true,
  "dependencies": {
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "5.2.1",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "webpack-dev-server": "^3.11.1"
  }
}

Not actually too different. But… do you have to (or is it advised that you?) do something with your npm dependencies on upgrading an app to a new rails version?

The Rails 6.1 package.json says that ^6.0.0 is fine for most of the @rails/ dependencies… but is this true? There is a 6.1.0 and a 6.1.1 of eg @rails/actioncable – but if you upgraded a Rails 6.0.0 app to 6.1, it’s probably using @rails/actioncable 6.0.0 – is it important that you update it to be using 6.1.0 or 6.1.1 instead?

  • Is Rails 6.1 generating a wrong spec in package.json, should it be generating one insisting on at least 6.1.0 of these rails deps?

  • Upon upgrading, is there something you should do to upgrade your @rails/ dependencies, and should the Upgrading Rails guide explain this?

The 6.1 package.json says "@rails/webpacker": "5.2.1",, whereas the 6.0 package.json says "@rails/webpacker": "4.3.0".

Upon upgrading my app from 6.0 to 6.1, do I need to edit my package.json for @rails/webpacker?

In general, I still feel pretty unsure in my use of webpacker. I am not certain what I should be doing here upon upgrades; I think perhaps the Upgrading Rails guide should address it?

2 Likes

Great question! While upgrading I was promted to upgrade one of the dependencies, but not all.

Great question! While upgrading I was promted to upgrade one of the dependencies, but not all.

I didn’t run into any prompt. Prompted by what step/action, could you tell/remember? I don’t think rails app:update for instance does anything with yarn dependencies/package.json? i am curious what does and what resulted in that prompt you mention.

It suggested me to update Stimulus and Stimulus Reflex (?) to be compatible, but I’m not sure what action. I ran the suggested upgrade command.

Getting Started with Rails — Ruby on Rails Guides has no mention of webpack(er). Any help in this area requires going to bloggers. Keeping docs up to date while the landscape is changing is tough.

While I’m at it, app/javascripts/should be app/webpack/ or app/webpacker by default.

And your comment is on upgrading which is different than a new app which the guides would focus on.

I hope Rails 7 gets rid of the npm/yarn requirement. 6.x would have been a terrible nightmare (aka dream to be forgotten)