zetachang / react-native-dotenv

A Babel preset let you import application configs from .env file (zero runtime dependency)
MIT License
916 stars 68 forks source link

...react-native-dotenv"' has no exported member 'USER_CLIENT_ID'. #76

Open chrissnape opened 4 years ago

chrissnape commented 4 years ago

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?

cristian-calugar commented 4 years ago

I have the same problem. Is this library intended to be used with typescript?

fermmm commented 4 years ago

I have the same problem, currently my workaround is this:

// @ts-ignore
import { API_KEY, ANOTHER_CONFIG } from "react-native-dotenv";
nonameolsson commented 4 years ago

I have the same problem. Sadly this library doesn't work well with TypeScript...

klaaz0r commented 4 years ago

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.

alexbrazier commented 4 years ago

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';
}
ricardoribas commented 4 years ago

The @types/react-native-dotenv is not enough to make it work. As @alexbrazier stated, a declaration file is also needed.