Can't get environment variable after eas build - react-native

After eas build can't access to name of channel of build`
"staging": {
"node": "14.21.1",
"channel": "staging",
"distribution": "internal",
"env": {
"APP_ENV": "staging"
}
}
that settings from my eas.json to env which I'm trying to build.
const config = getConfig(process.env.APP_ENV)
`
And I'm trying to get env depend on build, but it doesn't work(process.env.APP_ENV=undefined instead of "staging")
I already tried to get access by Contants

Related

Updates.channel is coming as null after setting up expo-updates

In my project I am using expo-sdk:43 along with expo-updates.
I have setup the channel property in eas.json file.
{
"cli": {
"version": ">= 0.52.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"channel":"dev"
},
"preview": {
"android": {
"buildType": "apk"
},
"channel":"preview"
},
"production": {}
},
"submit": {
"production": {}
}
}
I have tried to publish my updates through EAS update, but it is not working and the app is not receiving any update. I have tried to do an apk build for the application, and tried to get the output of Updates.Channel and it is outputting as undefined.
eas build -p android --profile --preview
eas update --branch preview --message "update"
But, when I build the app, the build is successful, in the eas logs I can see that it shows that channel property has also been configured.
Can someone please help what might be the possible issue in this case?
I have also tried to do the same steps with an expo-init command (But with expo sdk:47) and minimal app setup and it is working as expected.

Expo - How to run eas submit for internal testing in google play

Im using expo with eas build and eas submit for releasing an android app, when I do eas submit it automatically uploads the build and releases to the store.
Is it possible to run eas submit to upload to the internal testing track in the google play console?
My goal is to automate the process where I only upload the build for internal testing and once is tested release to the store by promoting the internal build.
I was able to do this by setting the track to internal in the eas.json file specifically in the submit section reference https://docs.expo.dev/submit/eas-json/:
{
"build": {
"development": {
....
},
"production": {
"channel": "production",
"distribution": "store",
}
},
"submit": {
"production": {
"android": {
"track": "internal" // (enum: production, beta, alpha, internal)
},
"ios": {
}
}
}
}

Parametrize android package and ios bundle id with EAS on Bare workflow

I'm currently working on a expo project and I had the bundle configuration parametrized with environment variables declared on eas.json and used on app.config.ts.
Some like this
eas.json
{
"cli": {
"version": ">= 0.48.2"
},
"build": {
"develop": {
"distribution": "store",
"env": {
"ENVIRONMENT": "develop"
},
"releaseChannel": "dev-v1"
},
"production": {
"releaseChannel": "prod-v1",
"env": {
"ENVIRONMENT": "production"
},
"distribution": "store"
}
}
app.config.ts
//removed a lot of not relevant code
ios: {
supportsTablet: true,
bundleIdentifier: getBundleId(), // returns correct bundle id based on ENVIRONMENT variable.
buildNumber: '1.0.4',
},
android: {
adaptiveIcon: {
foregroundImage: './assets/adaptive-icon.png',
backgroundColor: '#FFFFFF',
},
package: getBundleId(), // same of ios BundleIdentifier
versionCode: 104,
},
But now, for some requirements I have to eject the project into the bare workflow, and because of that I'm getting the follow message when I want to generate a new build with eas (with eas build -p=ios --profile=production)
Specifying "ios.bundleIdentifier" in app.config.ts is deprecated for bare workflow projects.
EAS Build depends only on the value in the native code. Please remove the deprecated configuration.
Does exist any way to keep bundleIdentifier, packageId and also the app schema parametrized by environment after eject?

"expo publish" not working for app built with EAS + expo-dev-client

I'm using the new expo-dev-client and EAS workflow to attempt development with expo, while also including native dependencies (react-native-firebase in my case).
I've managed to build and install a preview of my app with EAS:
eas build --platform ios --profile staging
Where my "staging" profile is setup in eas.json like so:
{
"cli": {
"version": ">= 0.35.0"
},
"build": {
"production": {
"releaseChannel": "prod-v0",
"node": "14.17.4",
"ios": {
"cocoapods": "1.11.2",
"autoIncrement": "buildNumber"
}
},
"staging": {
"extends": "production",
"releaseChannel": "staging",
"distribution": "internal"
},
...
},
...
}
Note the releaseChannel is set to "staging" too.
So far so good. The app is building and I can install it on my device and confirm the releaseChannel using the expo-updates module with Updates.releaseChannel
Now I'd like to publish a pure javascript change, so I run...
expo publish --release-channel staging
But this gives the following warning (which I assume is why I don't see the update on my device):
ios: Expo.plist key: "EXUpdatesReleaseChannel": The value passed to the
--release-channel flag is to "staging", but it is set to "default".
So what/where is "Expo.plist", why isn't it in-sync, and how can I update it?
Update:
So I deleted the iOS folder from a previous expo run:ios build. The warning is now gone when running expo publish --release-channel staging. But still nothing seems to happen on my app - it still doesn't update.

npm: How to set NODE_ENV in Windows (10)?

I am trying to add an npm script in package.json that sets NODE_ENV before doing something else (like running webpack). But although the syntax seems to be correct, NODE_ENV is not set when running under Windows 10.
Test script
"scripts": {
"test": "SET NODE_ENV=debug && echo %NODE_ENV%" }
The result from npm run test is "production" (provided NODE_ENV was set to "production" before running the script). Should be "debug".
What could be wrong? I even tried cross-env with no success.
Edit
To clarify my question: I cannot set any environment variable under Windows 10. And I need to call SET because I am running the script under Windows (10). Seems to be some rights problem (scripts not allowed to set environment variables?).
Another (or the actual) question would be: How can I create one script to build (using webpack) with creating minified versions of JavaScript files (for production), and one script to create non-minified versions (for development). So far I use following approach (see comments for the important parts):
Edit 2
I did not now that this probably made a difference, but in case it does: I worked with an React app created with create-react-app. I found the answer to my question, see below.
package.json:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
// Scipts for build for development and for production
"build-dev": "SET NODE_ENV=debug webpack",
"build-release": "SET NODE_ENV=production webpack"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",
"babel-preset-react": "^6.24.1",
"debug": "^2.6.4",
"webpack": "^2.4.1"
}
}
webpack.config.js:
const path = require('path');
var webpack = require('webpack');
// Check if in debug environment
var debug = process.env.NODE_ENV !== "production";
module.exports = {
context: path.join(__dirname, 'src'),
entry: ['./index.js'],
output: {
path: path.join(__dirname, 'www/js'),
filename: 'index.js',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader'],
}],
},
// Add the UglifyJs plugin only in debug mode
plugins: debug ? [] : [new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false })],
resolve: {
modules: [
path.join(__dirname, 'node_modules')
]
}
};
This fails because setting NODE_ENV does not work for some reason. Using the command prompt directly like in the scripts:
SET NODE_ENV = debug
webpack
works by the way. That's proof that the configuration is okay, but just the npm script cannot set NODE_ENV.
Just in case you are STILL having issues setting the NODE_ENV in Windows 10 - this will help you. In your package.json file add the following:
"test": "SET \"NODE_ENV=test\""
If you plan on pushing this to Heroku - you will have to "export" the variable and your string would look like this (you are escaping the Windows-NEEDED quotes with a slash):
"test": "export NODE_ENV=test || SET \"NODE_ENV=test\""
Lastly, if you need a following command like mocha then the line would look like this:
"test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha server/**/*.name_of_files_plus_test.js"
Hope this helps someone :) - Mike
I found the answer to my question in the meantime, basically in the create-react-app readme: Firstly in an app created with create-react-app NODE_ENV cannot be manually overridden. Secondly, when setting environment variables, their name must start with "REACT_APP_". This was the solution for me.
In package.json:
"scripts": {
...
"build:staging": "SET REACT_APP_ENVIRONMENT=Staging && npm run build"
}
In the code:
if (process.env.REACT_APP_ENVIRONMENT === "Staging") ...
Did you try?
set DEBUG=* & npm run test
Make sure debug already installed
npm install debug --save
UPDATE:
To set environment variable in windows use
set NODE_ENV=dev //for development environment
In your case
"scripts": {
"test": "NODE_ENV=dev && echo %NODE_ENV%" }