Same issue here. I tried checking typeof on process - it’s not treating it like a regular variable - it’s just hard crashing if process is in there at all.
I think something changed with how the replacement works. It used to work to do things like typeof process, but now it doesn’t.
You have to type the string exactly like process.env.APP_URL and that will get converted to your localhost URL when you build the extensions. I think you just have to use a try catch for production.
During shopify app dev, Node.js is running, so process.env is available, and the CLI automatically injects the local app URL.
However, after deployment, the Checkout UI Extension no longer runs in a Node.js environment, so process.env does not exist.
For now, I’m manually switching the app URL like this
//const APP_URL = "https://my-app-name.fly.dev"; // Production
const APP_URL: string = `${process.env.APP_URL}`; // Development
const fetchUrl: string = `${APP_URL}/api/payment-terms`;
This is not an ideal solution. If anyone knows a better way to automatically switch the app URL based on the environment, I’d really appreciate it if you could share it
Try / catch with a fallback work, but I want to comment on process.env not existing.
According to this threadshopify 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:
@S_W to avoid the manual switching, the cleanest pattern we’ve used is defining the URL once in your .env and .env.production files and letting esbuild handle the substitution at build time:
As dac514 pointed out, the key is making sure your .env filename matches your toml config name. Once that’s in place process.env.APP_URL gets replaced at deploy time and you never need to touch the code between environments.