Skip to content
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

Multi-env doesn't change #197

Closed
KonstantinZhukovskij opened this issue Jul 12, 2021 · 26 comments · Fixed by #198
Closed

Multi-env doesn't change #197

KonstantinZhukovskij opened this issue Jul 12, 2021 · 26 comments · Fixed by #198
Assignees
Labels
wontfix This will not be worked on

Comments

@KonstantinZhukovskij
Copy link

KonstantinZhukovskij commented Jul 12, 2021

Multi-env doesn't change. I always get variables from .env.development, most likely because this file is the first in the folder. I have the folder with 3 files: .env.development .env.staging .env.production. I've tried cleaning, reinstalling, and many more options, but nothing seems to work.

My npm scripts:

"start:development": "NODE_ENV=development npx react-native start --reset-cache",
"start:staging": "NODE_ENV=staging npx react-native start --reset-cache",
"start:production": "NODE_ENV=production npx react-native start --reset-cache",

I also use the next script:

"babel-clear": "rimraf node_modules/.cache/babel-loader/*,"

My babel config:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'module:react-native-dotenv',
      {
        moduleName: '@env',
        path: './config/.env',
        blocklist: null,
        allowlist: null,
        safe: false,
        allowUndefined: true,
      },
    ],
  ],
};

In my file index.js

import { URL } from '@env';

"react": "17.0.1",
"react-native": "0.64.1",
"react-native-dotenv": "^3.0.0",

@github-actions
Copy link

Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/197

@goatandsheep
Copy link
Owner

How are you setting which environment you're using for your server? Are you using node_env? App_env? Setting it in your configs? Let's figure this out.

@KonstantinZhukovskij
Copy link
Author

Updated. Please see in my question

@KonstantinZhukovskij
Copy link
Author

I understand correctly that NODE_ENV indicates which file to use?

@goatandsheep
Copy link
Owner

Try applying the environment setting to your run script instead and let me know what happens

@KonstantinZhukovskij
Copy link
Author

Could you give me an example?

@goatandsheep
Copy link
Owner

Sorry for the delay. I'm just doing a bit of research into the problem

@KonstantinZhukovskij
Copy link
Author

Did you manage to reproduce it?

@goatandsheep
Copy link
Owner

Working on it here https://github.com/goatandsheep/react-native-dotenv-metro-demo

@KonstantinZhukovskij
Copy link
Author

Also tell me please, can I get a variable NODE_ENV from other places? For example from gitlab CI?

@goatandsheep
Copy link
Owner

so I did find a bug actually. On gitlab CI my recommendation would be to do the same thing, which is run NODE_ENV=test staging isn't recommended but might work.

@goatandsheep
Copy link
Owner

will be fixed in v3.1.1

@goatandsheep
Copy link
Owner

@KonstantinZhukovskij if this change helps you, I request if you can make a donation, please do

@KonstantinZhukovskij
Copy link
Author

KonstantinZhukovskij commented Jul 13, 2021

I updated and it works great with npm scripts. Thank you very much for your work.

@KonstantinZhukovskij
Copy link
Author

@goatandsheep I asked yesterday about whether I can set the NODE_ENV constant from other places, for example, from gitlab CI? Now I tried to build a test assembly and got a production environment everywhere. Could this be a library problem? What are the ways to create a constant NODE_ENV?

@goatandsheep
Copy link
Owner

That's bizarre! In test, you should get test. I don't think I know what you mean by set node_env everywhere. Can you please expand on that?

@goatandsheep goatandsheep reopened this Jul 13, 2021
@github-actions
Copy link

Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/197

@KonstantinZhukovskij
Copy link
Author

KonstantinZhukovskij commented Jul 13, 2021

@goatandsheep This is part of my code inside the gitlab CI. I am trying to understand whether it is possible to indicate the environment in this way? If I specify the NODE_ENV constant here, is it the same as I specified in the npm script start:staging": "NODE_ENV=staging ?

firebase (stage):
  extends: .app-deploy
  stage: staging
  environment:
    name: stage
  variables:
    BUILD_DESTINATION: 'firebase'
    APP_IDENTIFIER: 'myID'
    NODE_ENV: 'staging'

@goatandsheep
Copy link
Owner

So the module should support reading the global NODE_ENV. However, I haven't tested it in this way yet. Also, for adding process.env variables into the mix, that is also in a pending PR. Go take a look if you're interested #191

If you want "staging", don't use "stage". Also, if you're not using test, development, or production, you're in experimental territory that I do not advise on a tight timeline.

@KonstantinZhukovskij
Copy link
Author

If you want "staging", don't use "stage".

What do you mean?

@goatandsheep
Copy link
Owner

Sorry about that message that was sent from my phone. Let me expand:

Disclaimer: I haven't used firebase config, I just saw:

  environment:
    name: stage

so I assumed that it would use .env.stage? My apologies if I'm wrong.

I also don't know if this works, but I haven't tried:

  variables:
    NODE_ENV: 'staging'

I recommend you set verbose: true (new option!) to see what value of env is being loaded.

And regarding

  variables:
    BUILD_DESTINATION: 'firebase'
    APP_IDENTIFIER: 'myID'

These will only load if #191 is merged

@KonstantinZhukovskij
Copy link
Author

@goatandsheep Are you going to merge it?

@goatandsheep
Copy link
Owner

I'm waiting to see if I can get some support before I do as it's a major feature

@KonstantinZhukovskij
Copy link
Author

@goatandsheep Could you create a new branch with the latest changes and #191 ?

@KonstantinZhukovskij
Copy link
Author

KonstantinZhukovskij commented Jul 14, 2021

@goatandsheep I made a patch with your changes #191 and tested it, but it still doesn't work. I am not getting data from my environment files, although I did get the NODE_ENV constant. However, there is a problem with the NODE_ENV, it is always development.

@stale
Copy link

stale bot commented Sep 12, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Sep 12, 2021
@stale stale bot closed this as completed Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants