-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@env couldn't found #5
Comments
Hello @sumit96367 , after some research this is how I resolved it on my end
and in my babel.config.js I added this
Let me know if it works for you. |
@JPaul23 @sumit96367 @adrianhajdin |
Hello @sumit96367 and everyone else who has this problem, I've started with react native through JavaScriptMastery this week and I've been getting the same error. And here is my solution. I added this to my // app.config.js
import "dotenv/config"
export default {
// Default app.json
extra: {
// Default extra
rapidApiKey: process.env.RAPID_API_KEY,
// ...
}
} If you don't have dotenv installed: npm install --save-dev dotenv Then to call these enviroment variables: // useFetch.js
// ... imports
import Constants from "expo-constants"
const rapidApiKey = Constants.expoConfig.extra.rapidApiKey
// ... If you don't have expo-constants installed: npx expo install expo-constants |
Thank you for this solution. This is my first time of learning react-native. |
Hello coders! I found solution the next way:
npx expo install expo-constants expo-config
npm install --save-dev metro-react-native-babel-preset
const extra = require('./extra');
module.exports = {
expo: {
name: "react_native_jobs",
slug: "react_native_jobs",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/images/icon.png",
scheme: "myapp",
userInterfaceStyle: "automatic",
splash: {
image: "./assets/images/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff"
},
assetBundlePatterns: [
"**/*"
],
ios: {
supportsTablet: true
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#ffffff"
}
},
web: {
bundler: "metro",
output: "static",
favicon: "./assets/images/favicon.png"
},
plugins: [
"expo-router"
],
experiments: {
typedRoutes: true
},
extra: extra,
}
};
module.exports = {
RAPID_API_KEY: 'rapid_api_key',
};
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
['module:react-native-dotenv']
],
};
Hopefully, the original set-up works for the majority. If not, this approach could be a solution for someone who runs into the same problem as I did. Happy coding! |
@env could not be found within the project or in these directories:
node_modules
1 | import { useState, useEffect } from "react";
2 | import axios from "axios";
The text was updated successfully, but these errors were encountered: