react-native-dotenv
react-native-dotenv copied to clipboard
...react-native-dotenv"' has no exported member 'USER_CLIENT_ID'.
I'm importing an environment variable into a typescript file, all in the app works well, except in my IDE I am getting ...
Module '"../../../../../../Users/chris/Projects/xxxxx/node_modules/@types/react-native-dotenv"' has no exported member 'USER_CLIENT_ID'.
..due to tyepscript when importing.
import { USER_CLIENT_ID } from 'react-native-dotenv';
Could anyone help out please?
I have the same problem. Is this library intended to be used with typescript?
I have the same problem, currently my workaround is this:
// @ts-ignore
import { API_KEY, ANOTHER_CONFIG } from "react-native-dotenv";
I have the same problem. Sadly this library doesn't work well with TypeScript...
I tried some things but for now just made this:
const isProduction = process.env.NODE_ENV === "production";
interface Config {
API_URL: string;
}
const config: Config = {
API_URL: isProduction
? "https://api.brabble.fm/graphql"
: "http://localhost:3001/graphql"
};
Object.freeze(config);
export default config;
It's not rocket science but since this package only works with development/production env's it's not that much of a lost.
I've got it working with typescript by creating a file called env.d.ts
which defines the keys you use, e.g.:
declare module 'react-native-dotenv' {
export const USER_CLIENT_ID: string;
export const ENV: 'dev' | 'prod';
}
The @types/react-native-dotenv is not enough to make it work. As @alexbrazier stated, a declaration file is also needed.