You need to recreate production ENV locally to reproduce bugs

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

Last Updated: 2022-12-01

I pushed to a Rails app to Heroku but it failed during the compilation of webpack, causing the deploy process to abort early.

Yet I could not reproduce the bug locally when I set Rails to the production ENV.

After Googling, I found that the way to recreate the error locally was to set the ENV for BOTH Rails and node to "production" and run that task in the deploy process locally:

NODE_ENV=production RAILS_ENV=production rails assets:precompile --trace

As a side note on architecture and logging strategy: I was glad to see that the deploy script printed out each step as it was doing it, since this meant I could pinpoint the failing to try out locally:

Running: rake assets:precompile

Lesson

When recreating bugs locally, be sure to copy the full ENV of the deploy situation. (e.g. literally calling env on that machine might be useful to grab everything)

More narrowly, be aware that different ENV variables might be used to indicate development vs. production environment in each language (e.g. in JavaScript there is one; another in Ruby etc.)