react-native-template-obytes icon indicating copy to clipboard operation
react-native-template-obytes copied to clipboard

How to replicate the env management on this template?

Open mrevanzak opened this issue 1 year ago • 6 comments

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

  • [ ] Task 1
  • [ ] Task 2
  • [ ] Task 3

mrevanzak avatar Sep 23 '24 18:09 mrevanzak

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

yjose avatar Sep 24 '24 09:09 yjose

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

mrevanzak avatar Sep 25 '24 12:09 mrevanzak

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

yjose avatar Sep 25 '24 13:09 yjose

Had the same issue,

Make sure you install https://www.npmjs.com/package/ts-node

Also I removed it from 'env.js'

Instead of: const path = require('path'); const envPath = path.resolve(__dirname, .env.${APP_ENV});

I used: const APP_ENV = process.env.APP_ENV ?? 'development'; const envPath = ${__dirname}/.env.${APP_ENV};

I don't remember exactly the chain of issues, but I ended up adding this package and fixed it.

abo-rythm avatar Sep 29 '24 04:09 abo-rythm

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

yes i did that

mrevanzak avatar Oct 02 '24 05:10 mrevanzak

Had the same issue,

Make sure you install https://www.npmjs.com/package/ts-node

Also I removed it from 'env.js'

Instead of: const path = require('path'); const envPath = path.resolve(__dirname, .env.${APP_ENV});

I used: const APP_ENV = process.env.APP_ENV ?? 'development'; const envPath = ${__dirname}/.env.${APP_ENV};

I don't remember exactly the chain of issues, but I ended up adding this package and fixed it.

no luck for me :(

mrevanzak avatar Oct 02 '24 05:10 mrevanzak