Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

react-native-dotenv Unable to resolve module @env

$
0
0

I'm setting up this lib for TypeScript like here

my env:

API_KEY=someKey..

i'm setting up type/env.d.ts:

declare module '@env' {    export const API_KEY: string;}

my babel.config.ts:

   module.exports = function (api) {    api.cache(true);    return {        presets: ["babel-preset-expo"],        plugins: [            ["module:react-native-dotenv",                {                    moduleName: "@env",                    path: ".env",                },            ],        ],    };};

my config.ts:

import API_KEY from '@env'export default {API_KEY};

package.json:

"dependencies": {"@types/react-native-dotenv": "^0.2.0","expo": "~42.0.1","expo-status-bar": "~1.0.4","foo": "^0.0.7","moment": "^2.29.1","react": "16.13.1","react-dom": "16.13.1","react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz","react-native-config": "^1.4.5","react-native-dotenv": "^3.1.1","react-native-web": "~0.13.12","styled-components": "^5.3.0"  },

and this file where i use API_KEYweather.ts:

Import axios from "axios";import config from "../../config";class WeatherService {  FetchCoordinatesHandler(city) {    return axios.get(`weather`, {      params: {        q: city,        units: "metric",        appid: config.API_KEY      },    });  }  FetchWeatherByCoordinatesHandler({lon, lat}) {    return axios.get(`onecall`, {      params: {        lat: lat,        lon: lon,        units: "metric",        appid: config.API_KEY      },    });  }}const weatherServiceInstance = new WeatherService();export default weatherServiceInstance;

and i get this in the console:

    Android Bundling failed 8987ms    Unable to resolve module @env from C:\IT\ReactNative\weather-app\weather-app\config.js: @env could not be found within the project or in these directories:      node_modules      ..\node_modules> 1 | import API_KEY from '@env'    |                      ^  2 |  3 | export default {API_KEY};

enter image description here

please help :( I don't know what to do, I've looked all over the internet. maybe my dependencies don't have the up-to-date version of something

ATTENTIONwhen i change my module from @env to 'react-native-dotenv' i'm still get error but some other:

Android Bundling failed 5334ms    Unable to resolve module fs from C:\IT\ReactNative\weather-app\weather-app\node_modules\react-native-dotenv\index.js: fs could not be found within the project or in t    hese directories:      node_modules      ..\node_modules> 1 | const {readFileSync} = require('fs')        |                                 ^      2 | const dotenv = require('dotenv')      3 |      4 | function parseDotenvFile(path, verbose = false) {

enter image description here

i hope anyone help me, thanks :)


Viewing all articles
Browse latest Browse all 6287

Trending Articles