react-native-dotenv icon indicating copy to clipboard operation
react-native-dotenv copied to clipboard

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

Open chrissnape opened this issue 5 years ago • 6 comments

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?

chrissnape avatar Jan 14 '20 15:01 chrissnape

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

cristian-calugar avatar Jan 22 '20 08:01 cristian-calugar

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

// @ts-ignore
import { API_KEY, ANOTHER_CONFIG } from "react-native-dotenv";

fermmm avatar Jan 23 '20 03:01 fermmm

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

nonameolsson avatar Jan 24 '20 07:01 nonameolsson

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.

klaaz0r avatar Feb 04 '20 08:02 klaaz0r

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';
}

alexbrazier avatar Feb 12 '20 11:02 alexbrazier

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

ricardoribas avatar Apr 15 '20 13:04 ricardoribas