After months of tangling with this error on and off, it was because I was setting NODE_ENV=production all along. I removed that and it worked.
NODE_ENV=production