I'm confused as to why a function I export from one React TypeScript module fails when imported into another module.
export const apiUrl = () : string => (process.env.NODE_ENV === 'development') ?
"https://localhost:5001" : "https://my.azure.site.net";
I'm aware this is not the best way to set environment-specific info but it seemed like an expedient way to do this as a quick way to test the Azure service.
When I import apiUrl into other modules I get the TypeError.
import { apiUrl } from './App';
console.log(apiUrl());
TypeError: App_1.apiUrl is not a function. (In 'App_1.apiUrl()', 'App_1.apiUrl' is undefined)
And the function is undefined. So much for expedience. I've tried a couple of permutations, including exporting a const string:
export const apiUrl = (process.env.NODE_ENV === 'development') ? "https://localhost:5001" : "https://my.azure.site.net";
In all cases the imported object is undefined.
Update: I've established that if I use the string or method inside a class method then it works, i.e. when I call it in the componentDidMount method. What am I missing about scope here?