When running expo start
it seems, app.config.js
is called more than once. Is it something normal?
For me, this causes console.log to write same logs multiple times and the build numbers to be incremented multiple times (possibly to be used in an inconsistent way within the whole expo start
process).
In the documents Configuration with app.json / app.config.js - Expo Documentation also uses console.log
and running that code also generate multiple logs.
So shall the function within app.config.js
be a pure function?
expo diagnostics
output:
Expo CLI 3.21.3 environment info:
System:
OS: macOS 10.15.5
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 13.6.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.6/11E708 - /usr/bin/xcodebuild
npmPackages:
expo: ^37.0.0 => 37.0.11
react: 16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
npmGlobalPackages:
expo-cli: 2.2.0
Hey @mehmetkaplan ,
Thanks for bringing this to our attention. Would you mind creating a github issue here ? Addressing this issue there will be a better course of action than on the forums.
Cheers,
Adam
Sure @adamjnav , thanks for the answer.
Here is the issue I opened:
opened 02:36AM - 20 Jul 20 UTC
closed 06:55PM - 23 Jul 20 UTC
<!--
# READ THIS FIRST, PLEASE!
We're looking to keep questions on our forum… s and bug reports on the GitHub repo -- please choose whichever you feel is more appropriate for your issue:
- For questions and help using Expo CLI, post in our community forums (log in with your Expo developer account): https://forums.expo.io/c/expo-cli
- File a bug on the Expo CLI repo (for bugs related to the Expo CLI tools): https://github.com/expo/expo-cli/issues/new
- File a bug on the main Expo repo (for other bugs): https://github.com/expo/expo/issues/new
- Request a feature on Canny: https://expo.canny.io/feature-requests
Thanks for reporting the issue you found with Expo CLI!
-->
<!--
# Required format for issues
Please make our job easier by filling this template out to completion.
-->
## Description
<!--
1-2 sentences describing the problem you're having or the feature you'd like to request
-->
When `expo start` is called, `app.config.js` is called more than once. This makes tasks like managing build numbers, logging current build parameters, etc harder.
## Expected Behavior
When `expo start` starts execution, it would be better it forms the final app.json only once, and reuses that final app.json every time it needs.
<!--
What action did you perform, and what did you expect to happen?
-->
## Observed Behavior
Using same method mentioned in [related documentation](https://docs.expo.io/workflow/configuration/), when `expo start` is run the log is written multiple times, which implies most of the (if not each) times app.json is needed the exported function in `app.config.js` is called again and again.
```
export default ({ config }) => {
console.log(config.name); // prints 'My App'
return {
...config,
};
};
```
<!--
What actually happened when you performed the above actions?
If there's an error message, please paste the _full terminal output and error message_ in this code block: -->
This causes build number management within `app.config.js` near impossible, logs to be generated unnecessary times, the process itself to slow down.
## Environment
<!--
Please run `expo diagnostics` in the project folder and copy the output here:
Also specify:
- Phone/emulator/simulator platform, model and version:
-->
```
mehmetkaplan@MACOS:app-config-test$ expo diagnostics
Expo CLI 3.22.3 environment info:
System:
OS: macOS 10.15.5
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.18.2 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.6/11E708 - /usr/bin/xcodebuild
npmPackages:
expo: ~38.0.8 => 38.0.8
react: ~16.11.0 => 16.11.0
react-dom: ~16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
react-native-web: ~0.11.7 => 0.11.7
npmGlobalPackages:
expo-cli: 2.2.0
```
## Reproducible Demo
<!--
Please provide a minimized reproducible demonstration of the problem you're reporting.
Issues that come with minimal repro's are resolved much more quickly than issues where a maintainer has to reproduce themselves.
-->
In the below demo please note the text `app-config-test` is coming from the `app.config.js` and it continues to be logged even after the QR code is generated.
```
mehmetkaplan@MACOS:test$ figlet app-config-test
__ _ _ _
__ _ _ __ _ __ ___ ___ _ __ / _(_) __ _ | |_ ___ ___| |_
/ _` | '_ \| '_ \ _____ / __/ _ \| '_ \| |_| |/ _` |_____| __/ _ \/ __| __|
| (_| | |_) | |_) |_____| (_| (_) | | | | _| | (_| |_____| || __/\__ \ |_
\__,_| .__/| .__/ \___\___/|_| |_|_| |_|\__, | \__\___||___/\__|
|_| |_| |___/
mehmetkaplan@MACOS:test$ expo init app-config-test
? Choose a template: expo-template-blank
🧶 Using Yarn to install packages. You can pass --npm to use npm instead.
✔ Downloaded and extracted project files.
✔ Installed JavaScript dependencies.
✅ Your project is ready!
To run your project, navigate to the directory and run one of the following yarn commands.
- cd app-config-test
- yarn start # you can open iOS, Android, or web from here, or run them directly with the commands below.
- yarn android
- yarn ios
- yarn web
mehmetkaplan@MACOS:test$ cd app-config-test/
mehmetkaplan@MACOS:app-config-test$ echo "
> export default ({ config }) => {
> console.log(config.name); // prints 'My App'
> return {
> ...config,
> };
> };
> " > app.config.js
mehmetkaplan@MACOS:app-config-test$ yarn start
yarn run v1.21.1
$ expo start
app-config-test
Starting project at /Users/mehmetkaplan/ActiveCodes/test/app-config-test
app-config-test
Expo DevTools is running at http://localhost:19002
Press d to open DevTools now, or shift-d to always open it automatically.
app-config-test
app-config-test
app-config-test
app-config-test
Starting Metro Bundler on port 19001.
app-config-test
app-config-test
app-config-test
exp://172.20.10.4:19000
[REMOVED QR CODE]
To run the app with live reloading, choose one of:
• Sign in as @mehmetkaplan in Expo client on Android or iOS. Your projects will automatically appear in the "Projects" tab.
• Scan the QR code above with the Expo app (Android) or the Camera app (iOS).
• Press a for Android emulator, or i for iOS simulator, or w to run on web.
• Press e to send a link to your phone with email.
Expo Press ? to show a list of all available commands.
Logs for your project will appear below. Press Ctrl+C to exit.
app-config-test
Stopping packager...
› Closing Expo server
› Stopping Metro bundler
Packager stopped.
✨ Done in 71.18s.
mehmetkaplan@MACOS:app-config-test$
```
Please let me know if anything (content, place of the issue, etc) is missing or wrong.
1 Like
Meanwhile as a workaround, I am preparing the app.json
file in advance automatically. To do that I wrote a small js code to be manually run through node just before running expo build
.
const fs = require("fs");
const appJsonPrepare = () => {
// increment build number
let buildNumber;
try{
buildNumber = Number(fs.readFileSync('./build-counter.txt').toString().split('\n')[0]) + 1;
} catch (err){
buildNumber = 1;
}
if (!buildNumber) buildNumber = 1;
fs.writeFileSync('./build-counter.txt', `${buildNumber}`);
// read existing app.json as the base
const appJson = JSON.parse(fs.readFileSync('./app.json').toString());
// modify new values
appJson.expo.ios.buildNumber = `${buildNumber}`;
if (!(appJson.expo.android)) appJson.expo.android = {};
This file has been truncated. show original
system
Closed
August 9, 2020, 5:16am
5
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.