obytes / react-native-template-obytes

📱 A template for your next React Native project: Expo, PNPM, TypeScript, TailwindCSS, Husky, EAS, GitHub Actions, Env Vars, expo-router, react-query, react-hook-form.
https://starter.obytes.com
MIT License
2.16k stars 319 forks source link

How to replicate the env management on this template? #362

Open mrevanzak opened 4 days ago

mrevanzak commented 4 days ago

Summary:

I have an existing app that already running and i wanna replicate how this template manages the env. but i cant get it running. always fails on Unable to resolve module path. if i installed 'path' as dev deps it will shows another error because of dotenv doesnt work for react native (?)

Steps to reproduce:

ran the build:staging script

Expected behavior:

successfully build and running

Additional notes:

Tasks

yjose commented 3 days ago

Yes, technically you can add the environment setup to any project that uses the Expo prebuild system. Here is an explanation of the problem you are experiencing:

"Unable to resolve module path" means you are trying to import the path Node.js module into your app, which will not work because the runtime is different. This issue arises because you are importing the ./env.js file into a file located in the ./src folder, which Metro is attempting to bundle.

To resolve this, ensure you import your environment variables from @env, which should be an alias for ./src/core/env.js, instead of ./env.js.

let's me know if the issue still persist after those checks

mrevanzak commented 2 days ago

i already make sure bunch of time if it was correct. i also tried to not use the alias but still no luck

yjose commented 2 days ago

Make sure you are starting the metro server without cache pnpm start -c