How to replicate the env management on this template?
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
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
i already make sure bunch of time if it was correct. i also tried to not use the alias but still no luck
Make sure you are starting the metro server without cache pnpm start -c
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.
Make sure you are starting the metro server without cache pnpm start -c
yes i did that
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 :(