zetachang / react-native-dotenv

A Babel preset let you import application configs from .env file (zero runtime dependency)
MIT License
915 stars 68 forks source link

Changing environment variables in files .env and .env.production not picked up until reboot on OSX #79

Closed t-ricci-enhancers closed 4 years ago

t-ricci-enhancers commented 4 years ago

This is a Bug report.

As stated in the title, for me and other members of my team, changing the contents of the .env and .env.production files require a full reboot of the computer in order to be picked up on the app build.

This is my current specs:

macOS Catalina 10.15.4 (19E266) Xcode Version 11.4 (11E146) Node version v13.10.1 (I'm using Oh-My-Zsh and Node version manager NVM) Npm version 6.14.4 react-native-dotenv version 0.2.0 react-native version 0.61.4 react version 16.9.0 metro version 0.56.3 @babel/core version 7.7.2

I've already tried cleaning the project's folder (and obviously restarting the metro bundler) but it didn't work until I rebooted the mac.

Here's the shell script that I'm using to clean react-native build and cache files:

react-native-clean() {
    if [ ! -f "react-native.config.js" ]; then
        echo >&2 "Probably not a react-native project root folder!"
        return 1
    else
        echo "Detected react-native project root folder..."
    fi

    if [ -x "command -v watchman" ]; then
        watchman watch-del-all
    fi

    if [[ -d "$TMPDIR"react-* ]]; then
        rm -rf "$TMPDIR"react-*
    fi

    if [[ -d /tmp/react-* ]]; then
        rm -rf /tmp/react-*
    fi

    if [[ -d $TMPDIR/metro-* ]]; then
        rm -rf $TMPDIR/metro-*
    fi

    if [[ -d /tmp/metro-* ]]; then
        rm -rf /tmp/metro-*
    fi

    if [[ -d "node_modules" ]]; then
        rm -rf node_modules
    fi

    if [ -x "$(command -v npm)" ]; then
        echo "Cleaning node_modules and reinstalling..."
        npm cache clean --force && npm ci
    else
        echo >&2 "Could not find node_modules or npm command\!"
    fi

    if [ -d "ios" ]; then
        echo "Cleaning iOS..."

        cd ios

        if [ -x "$(command -v pod)" ]; then
            echo "Reinstalling Pods..."
            rm -rf Pods && pod install --repo-update && pod update
        else
            echo "Command pod not found"
        fi

        if [ -x "$(command -v xcodebuild)" ]; then
            echo "Cleaning Xcode build..."
            if [ -z "$(xcodebuild clean)" ]; then
                echo "Xcode build cleaned correctly with xcodebuild"
            else
                rm -rf build && echo "Removed Xcode build folder correctly"
            fi
        else
            echo "Command xcodebuild not found"
        fi

        cd ..
    else
        echo >&2 "Could not find ios folder\!"
    fi

    if [ -d "android" ] && [ -f "android/gradlew" ]; then
        echo "Cleaning Android..."

        cd android
        ./gradlew clean

        cd ..

        if npx --version >/dev/null 2>&1; then
            npx jetify
        fi
    else
        echo >&2 "Could not find android folder or gradlew executable\!"
    fi
}
XebniDev commented 4 years ago

The same issue, have no solution yet.

macOS Catalina 10.15.3 Xcode Version 11.4 (11E146) Node version v12.16.1 Npm version 6.13.4 react-native-dotenv version 0.2.0 react-native version 0.61.4 react version 16.9.0 metro version 0.56.0 @babel/core version 7.8.7

amamiri commented 4 years ago

Did you guys try what is suggested in the README... A change in import statement (adding a space or something) makes the changes in the env file picked up.

t-ricci-enhancers commented 4 years ago

It worked closing metro-bundler and running it again with the reset cache option: react-native start --reset-cache instead of react-native start (or npm start -- --reset-cache if you have the npm start script in the package.json`)