Delete webpack relics if code changes are not picked up

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the rails category.

Last Updated: 2021-05-15

I had some integration tests that were failing due to the presence of a bad third party (test) API key used in the JavaScript. I passed this API key via Ruby as follows:

# config/initializers/webpack.rb
Webpacker::Compiler.env['FACEBOOK_PIXEL_ID'] =
  Config['facebook_pixel_id']

Anyway the original key, the bad one, was 11111..., as showed up in the error below:

https://connect.facebook.net/signals/config/1111111111111111?v=2.9.2&r=stable - Failed to load resource: the server responded with a status of 404 ()

But when I changed the key to 22222222, a valid one, I still saw the same error message. (Restarting spring did not help either.)

The trick to solving it was to force webpack to regenerate the assets. I did this by deleting the generated packs in public/packs.

Lesson

Watch out for state persisted by web-pack. It can survive server restarts and cause changes in the code not to be picked up.