I experienced this problem.
Try / catch with a fallback work, but I want to comment on process.env not existing.
According to this thread shopify app deploy uses shopify.app.YOURNAME.toml and .env.YOURNAME where YOURNAME is some config name. I did not have such a file. When I created an env file that matched my toml file name file I saw:
Using shopify.app.YOURNAME.toml for default values:
Change to:
Using .env.YOURNAME for default values:
In the deploy process.
Just putting it out therre.
EDIT: Source code confirms it: Vars like process.env.X will be substituted by esbuild define, but matching config needs to be found.