Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

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

Open
chrissnape opened this issue Jan 14, 2020 · 6 comments
Open

Comments

@chrissnape
Copy link

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
Copy link

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

@fermmm
Copy link

fermmm commented Jan 23, 2020

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

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

@nonameolsson
Copy link

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

@klaaz0r
Copy link

klaaz0r commented Feb 4, 2020

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
Copy link

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
Copy link

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

Clumsy-Coder added a commit to Clumsy-Coder/myStocksRN that referenced this issue May 7, 2020
The project will use .env file to store build version and API_KEY

NOTE: typescript module for react-native-dotenv has to be created. Placed in src/config/env.d.ts
This module ensure Typescript that the environment variable in .env do exist and cause no issue

check zetachang/react-native-dotenv#76 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants